ZENLLC commited on
Commit
225b06d
·
verified ·
1 Parent(s): e02eae9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load multiple open-source models (lightweight for CPU-basic)
5
+ models = {
6
+ "DistilGPT-2": pipeline("text-generation", model="distilgpt2"),
7
+ "GPT2 (Small)": pipeline("text-generation", model="gpt2"),
8
+ "DialoGPT-small": pipeline("text-generation", model="microsoft/DialoGPT-small"),
9
+ "OPT-350M": pipeline("text-generation", model="facebook/opt-350m"),
10
+ "Bloom-560M": pipeline("text-generation", model="bigscience/bloom-560m"),
11
+ }
12
+
13
+ def compare_models(user_input, max_new_tokens=100, temperature=0.7):
14
+ results = {}
15
+ for name, generator in models.items():
16
+ try:
17
+ output = generator(user_input, max_new_tokens=max_new_tokens, temperature=temperature)[0]["generated_text"]
18
+ results[name] = output
19
+ except Exception as e:
20
+ results[name] = f"⚠️ Error: {str(e)}"
21
+ return [results[m] for m in models.keys()]
22
+
23
+ with gr.Blocks(css="style.css") as demo:
24
+ gr.Markdown("## 🤖 Open-Source Model Comparator\n"
25
+ "Type a prompt once, see how different open-source LLMs respond side-by-side.")
26
+
27
+ with gr.Row():
28
+ user_input = gr.Textbox(label="Your prompt", placeholder="Ask something like 'Write a short poem about the stars'...", lines=2)
29
+ generate_btn = gr.Button("Generate", variant="primary")
30
+
31
+ with gr.Row():
32
+ max_tokens = gr.Slider(20, 200, value=100, step=10, label="Max new tokens")
33
+ temp = gr.Slider(0.1, 1.0, value=0.7, step=0.1, label="Creativity (temperature)")
34
+
35
+ with gr.Row():
36
+ outputs = [gr.Textbox(label=name, elem_classes="output-box", interactive=False) for name in models.keys()]
37
+
38
+ examples = [
39
+ ["Explain quantum computing in simple terms."],
40
+ ["Write a haiku about autumn leaves."],
41
+ ["What are the pros and cons of nuclear energy?"],
42
+ ["Describe a futuristic city in the year 2200."],
43
+ ["Write a funny short story about a robot learning to cook."],
44
+ ]
45
+ gr.Examples(examples=examples, inputs=[user_input])
46
+
47
+ generate_btn.click(compare_models, inputs=[user_input, max_tokens, temp], outputs=outputs)
48
+ user_input.submit(compare_models, inputs=[user_input, max_tokens, temp], outputs=outputs)
49
+
50
+ if __name__ == "__main__":
51
+ demo.launch()