Crimson206 commited on
Commit
1e7b7d7
Β·
verified Β·
1 Parent(s): 7152913

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -1,6 +1,20 @@
 
 
 
1
  import gradio as gr
 
2
 
3
- def slow_echo(message, history):
4
- return message
5
 
6
- demo = gr.ChatInterface(slow_echo).queue().launch()
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.chat_models import ChatOpenAI
2
+ from langchain.schema import AIMessage, HumanMessage
3
+ import openai
4
  import gradio as gr
5
+ import os
6
 
7
+ os.environ["OPENAI_API_KEY"] = "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" # Replace with your key
 
8
 
9
+ llm = ChatOpenAI(temperature=1.0, model='gpt-3.5-turbo-0613')
10
+
11
+ def predict(message, history):
12
+ history_langchain_format = []
13
+ for human, ai in history:
14
+ history_langchain_format.append(HumanMessage(content=human))
15
+ history_langchain_format.append(AIMessage(content=ai))
16
+ history_langchain_format.append(HumanMessage(content=message))
17
+ gpt_response = llm(history_langchain_format)
18
+ return gpt_response.content
19
+
20
+ gr.ChatInterface(predict).launch()