theotherdylan commited on
Commit
232d9d3
1 Parent(s): a6e2e1a
Files changed (2) hide show
  1. README.md +4 -0
  2. app.py +43 -0
README.md CHANGED
@@ -11,3 +11,7 @@ license: mit
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
+
15
+
16
+ Chat with tinydolphin.
17
+
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ollama
2
+ import gradio
3
+
4
+
5
+ history = []
6
+
7
+
8
+ def get_history_messages():
9
+ messages = []
10
+ for user, assist in history:
11
+ messages.append({"role": "user", "content": user})
12
+ messages.append({"role": "assistant", "content": assist})
13
+ return messages
14
+
15
+
16
+ def predict(prompt):
17
+ response = ollama.chat(
18
+ model="tinydolphin",
19
+ messages=[
20
+ *get_history_messages(),
21
+ {"role": "user", "content": prompt}
22
+ ],
23
+ stream=True
24
+ )
25
+ history.append((prompt, ""))
26
+ message = ""
27
+ for chunk in response:
28
+ message += chunk["message"]["content"]
29
+ history[-1] = (prompt, message)
30
+ yield "", history
31
+
32
+ with gradio.Blocks(theme='abidlabs/Lime', fill_height=True) as demo:
33
+ chat = gradio.Chatbot(scale=1)
34
+ with gradio.Row(variant="compact"):
35
+ prompt = gradio.Textbox(show_label=False, scale=6, autofocus=True)
36
+ button = gradio.Button(scale=1)
37
+
38
+ for handler in [button.click, prompt.submit]:
39
+ handler(predict, inputs=[prompt], outputs=[prompt, chat])
40
+
41
+
42
+ if __name__ == '__main__':
43
+ demo.launch()