from huggingface_hub import InferenceClient import gradio as gr client = InferenceClient( "mistralai/Mixtral-8x7B-Instruct-v0.1" ) def format_prompt(message, history): prompt = "" for user_prompt, bot_response in history: prompt += f"[INST] {user_prompt} [/INST]" prompt += f" {bot_response} " 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)