| import gradio as gr |
| from huggingface_hub import InferenceClient |
|
|
| |
| client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3") |
|
|
| |
| def format_prompt(message, history): |
| prompt = "<s>" |
| for user_prompt, bot_response in history: |
| prompt += f"[INST] {user_prompt} [/INST] {bot_response}</s> " |
| prompt += f"[INST] {message} [/INST]" |
| return prompt |
|
|
| |
| def generate(prompt, history, temperature, max_new_tokens, top_p, repetition_penalty): |
| formatted_prompt = format_prompt(prompt, history) |
| stream = client.text_generation( |
| formatted_prompt, |
| temperature=float(temperature), |
| max_new_tokens=int(max_new_tokens), |
| top_p=float(top_p), |
| repetition_penalty=float(repetition_penalty), |
| do_sample=True, |
| seed=42, |
| stream=True, |
| return_full_text=False, |
| ) |
| output = "" |
| for response in stream: |
| output += response.token.text |
| yield output |
|
|
| |
| with gr.Blocks(theme="soft") as demo: |
| gr.Markdown("### 📱 Multi‑Model Playground (Mobile Optimized)") |
|
|
| |
| with gr.Tab("Mistral Chat"): |
| gr.ChatInterface( |
| fn=generate, |
| chatbot=gr.Chatbot(layout="bubble", show_label=False), |
| additional_inputs=[ |
| gr.Dropdown([0.7, 0.9, 1.0], value=0.9, label="Temperature"), |
| gr.Dropdown([128, 256, 512], value=256, label="Max new tokens"), |
| gr.Dropdown([0.8, 0.9, 1.0], value=0.9, label="Top‑p"), |
| gr.Dropdown([1.0, 1.2, 1.5], value=1.2, label="Repetition penalty"), |
| ], |
| ) |
|
|
| |
| with gr.Tab("DALL·E 3 XL"): |
| gr.load("models/ehristoforu/dalle-3-xl-v2", src="spaces") |
|
|
| |
| with gr.Tab("Phi‑3 Mini"): |
| gr.load("models/microsoft/Phi-3-mini-4k-instruct", src="spaces") |
|
|
| |
| demo.launch(share=True) |