Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import InferenceClient
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
client = InferenceClient(
|
5 |
+
"mistralai/Mixtral-8x7B-Instruct-v0.1"
|
6 |
+
)
|
7 |
+
|
8 |
+
|
9 |
+
def format_prompt(message, history):
|
10 |
+
prompt = "<s>"
|
11 |
+
for user_prompt, bot_response in history:
|
12 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
13 |
+
prompt += f" {bot_response}</s> "
|
14 |
+
prompt += f"[INST] {message} [/INST]"
|
15 |
+
return prompt
|
16 |
+
|
17 |
+
def generate(prompt, history, email):
|
18 |
+
if not email:
|
19 |
+
return "Please provide your email address to use the app."
|
20 |
+
|
21 |
+
generate_kwargs = dict(seed=42)
|
22 |
+
|
23 |
+
formatted_prompt = format_prompt(f"{prompt}", history)
|
24 |
+
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
25 |
+
output = ""
|
26 |
+
|
27 |
+
for response in stream:
|
28 |
+
output += response.token.text
|
29 |
+
yield output
|
30 |
+
return output
|
31 |
+
|
32 |
+
|
33 |
+
additional_inputs=[
|
34 |
+
gr.Textbox(
|
35 |
+
label="Email",
|
36 |
+
placeholder="Enter your email",
|
37 |
+
interactive=True,
|
38 |
+
)
|
39 |
+
]
|
40 |
+
|
41 |
+
gr.ChatInterface(
|
42 |
+
fn=generate,
|
43 |
+
chatbot=gr.Chatbot(show_label=True, show_share_button=True, show_copy_button=True, likeable=True, layout="bubble"),
|
44 |
+
additional_inputs=additional_inputs,
|
45 |
+
title="Predict the Prompt - GDG Cloud Kolkata - GCCD 2024",
|
46 |
+
concurrency_limit=20,
|
47 |
+
).launch(show_api=False)
|