cutiee82 commited on
Commit
158f9d8
·
verified ·
1 Parent(s): ee075f0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+
4
+ client = InferenceClient("HuggingFaceTB/SmolLM2-1.7B-Instruct")
5
+
6
+ def chat(message, history):
7
+ stream = client.chat.completions.create(
8
+ messages=history,
9
+ max_tokens=1024,
10
+ stream=True
11
+ )
12
+ result = ""
13
+ for chunk in stream:
14
+ result += chunk.choices[0].delta.content
15
+ yield result
16
+ yield result
17
+
18
+ with gr.Blocks(
19
+ title="🤏 SmolLM Instruct",
20
+ css="footer {display: none !important}",
21
+ theme=gr.themes.Base(
22
+ primary_hue="red",
23
+ secondary_hue="red",
24
+ neutral_hue="neutral"
25
+ )
26
+ ) as app:
27
+ gr.Markdown("# 🤏 SmolLM Instruct")
28
+
29
+ gr.ChatInterface(
30
+ fn=chat,
31
+ type="messages",
32
+ examples=["Hi!"]
33
+ )
34
+
35
+ with gr.Accordion("ℹ️ About", open=False):
36
+ gr.Markdown(f"""
37
+ * Created by [🍒 cherry-ghosts community](https://hf.co/cherry-ghosts)
38
+ * Powered by [🤗 Inference API](https://hf.co/docs/api-inference)
39
+ * Running on [Gradio](https://gradio.app) v{gr.__version__}
40
+ """)
41
+
42
+ if __name__ == "__main__":
43
+ app.queue().launch(debug=True, ssr_mode=False)