Spaces:
Runtime error
Runtime error
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): | |
if not email: | |
return "Please provide your email address to use the app." | |
generate_kwargs = dict(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 = "" | |
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", | |
concurrency_limit=20, | |
).launch(show_api=False) |