yoon2566 commited on
Commit
86f2257
·
verified ·
1 Parent(s): e1c767b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -21
app.py CHANGED
@@ -1,27 +1,12 @@
1
- # This is a simple general-purpose chatbot built on top of LangChain and Gradio.
2
- # Before running this, make sure you have exported your OpenAI API key as an environment variable:
3
- # export OPENAI_API_KEY="your-openai-api-key"
4
-
5
- from langchain_openai import ChatOpenAI
6
- from langchain.schema import AIMessage, HumanMessage
7
  import gradio as gr
8
 
9
- model = ChatOpenAI(model="gpt-4o-mini")
10
-
11
- def predict(message, history):
12
- history_langchain_format = []
13
- for msg in history:
14
- if msg['role'] == "user":
15
- history_langchain_format.append(HumanMessage(content=msg['content']))
16
- elif msg['role'] == "assistant":
17
- history_langchain_format.append(AIMessage(content=msg['content']))
18
- history_langchain_format.append(HumanMessage(content=message))
19
- gpt_response = model.invoke(history_langchain_format)
20
- return gpt_response.content
21
 
22
- demo = gr.ChatInterface(
23
- predict,
24
- type="messages"
 
25
  )
26
 
27
  demo.launch()
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
+ def greet(name, intensity):
4
+ return "Hello, " + name + "!" * int(intensity)
 
 
 
 
 
 
 
 
 
 
5
 
6
+ demo = gr.Interface(
7
+ fn=greet,
8
+ inputs=["text", "slider"],
9
+ outputs=["text"],
10
  )
11
 
12
  demo.launch()