Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
hf_api_key = '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'
|
4 |
+
|
5 |
+
#FalcomLM-instruct endpoint on the text_generation library
|
6 |
+
#client = Client("https://api-inference.huggingface.co/models/tiiuae/falcon-40b-instruct", headers={"Authorization": f"Bearer {hf_api_key}"}, timeout=120)
|
7 |
+
#client = Client("https://wjmh73a2pphfr6ed.us-east-1.aws.endpoints.huggingface.cloud", headers={"Authorization": f"Bearer {hf_api_key}"}, timeout=120)
|
8 |
+
client = Client("https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct", headers={"Authorization": f"Bearer {hf_api_key}"}, timeout=120)
|
9 |
+
|
10 |
+
def generate(input):
|
11 |
+
output = client.generate(input,max_new_tokens=1024).generated_text
|
12 |
+
return output
|
13 |
+
|
14 |
+
def respond(message, chat_history):
|
15 |
+
#No LLM here, just respond with a random pre-made message
|
16 |
+
'''bot_message = random.choice(["Tell me more about it",
|
17 |
+
"Cool, but I'm not interested",
|
18 |
+
"Hmmmm, ok then"]) '''
|
19 |
+
bot_message = generate(message)
|
20 |
+
|
21 |
+
chat_history.append((message, bot_message))
|
22 |
+
return "", chat_history
|
23 |
+
|
24 |
+
with gr.Blocks() as demo:
|
25 |
+
chatbot = gr.Chatbot() #just to fit the notebook
|
26 |
+
msg = gr.Textbox(label="Prompt")
|
27 |
+
btn = gr.Button("Submit")
|
28 |
+
|
29 |
+
clear = gr.ClearButton(components=[msg, chatbot], value="Clear console")
|
30 |
+
|
31 |
+
btn.click(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
|
32 |
+
msg.submit(respond, inputs=[msg, chatbot], outputs=[msg, chatbot]) #Press enter to submit
|
33 |
+
demo.launch(height=240)
|