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