FloydTan1987 commited on
Commit
14782c9
β€’
1 Parent(s): dd9edd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -38
app.py CHANGED
@@ -1,42 +1,8 @@
1
  import gradio as gr
2
- import ollama
3
 
4
- def format_history(msg: str, history: list[list[str, str]], system_prompt: str):
5
- chat_history = [{"role": "system", "content":system_prompt}]
6
- for query, response in history:
7
- chat_history.append({"role": "user", "content": query})
8
- chat_history.append({"role": "assistant", "content": response})
9
- chat_history.append({"role": "user", "content": msg})
10
- return chat_history
11
 
12
- def generate_response(msg: str, history: list[list[str, str]], system_prompt: str):
13
- chat_history = format_history(msg, history, system_prompt)
14
- response = ollama.chat(model='llama2', stream=True, messages=chat_history)
15
- message = ""
16
- for partial_resp in response:
17
- token = partial_resp["message"]["content"]
18
- message += token
19
- yield message
20
 
21
- chatbot = gr.ChatInterface(
22
- generate_response,
23
- chatbot=gr.Chatbot(
24
- avatar_images=["cx.jpg", "agent.jpg"],
25
- height="64vh"
26
- ),
27
- additional_inputs=[
28
- gr.Textbox(
29
- "Behave as if you are order placer agent.",
30
- label="System Prompt"
31
- )
32
- ],
33
- title="Door Treats",
34
- description="Please ask any questions you may have about your order.πŸ€”",
35
- theme="soft",
36
- submit_btn="β¬… Send",
37
- retry_btn="πŸ”„ Regenerate Response",
38
- undo_btn="↩ Delete Previous",
39
- clear_btn="πŸ—‘οΈ Clear Chat"
40
- )
41
-
42
- chatbot.launch()
 
1
  import gradio as gr
 
2
 
3
+ def greet(name):
4
+ return "Hello " + name + "!"
 
 
 
 
 
5
 
6
+ demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
7
 
8
+ demo.launch()