File size: 2,072 Bytes
95973c2
742dfc9
95973c2
742dfc9
 
ae75b83
742dfc9
ae75b83
742dfc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae75b83
 
742dfc9
 
ae75b83
 
 
 
 
 
742dfc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
import gradio as gr
from huggingface_hub import InferenceClient

# Initialize Mistral client
client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")

# Prompt formatting for Mistral
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

# Generation function with streaming
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

# Build unified mobile-friendly interface
with gr.Blocks(theme="soft") as demo:
    gr.Markdown("### 📱 Multi‑Model Playground (Mobile Optimized)")

    # Tab 1: Mistral Chat
    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"),
            ],
        )

    # Tab 2: DALL·E 3 XL
    with gr.Tab("DALL·E 3 XL"):
        gr.load("models/ehristoforu/dalle-3-xl-v2", src="spaces")

    # Tab 3: Phi‑3 Mini
    with gr.Tab("Phi‑3 Mini"):
        gr.load("models/microsoft/Phi-3-mini-4k-instruct", src="spaces")

# Launch with share=True for mobile browser access
demo.launch(share=True)