Update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,62 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
models = {
|
| 6 |
-
"
|
| 7 |
-
"
|
| 8 |
-
"
|
| 9 |
-
"
|
| 10 |
-
"
|
| 11 |
}
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
with gr.Blocks(css="""
|
| 26 |
body {
|
| 27 |
-
background-color: #fffde7;
|
| 28 |
}
|
| 29 |
#title {
|
| 30 |
-
color: #6b4f26; /* Brown */
|
| 31 |
text-align: center;
|
| 32 |
-
font-size:
|
| 33 |
font-weight: bold;
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
#subtitle {
|
| 37 |
-
text-align: center;
|
| 38 |
-
color: #8d6e63;
|
| 39 |
-
font-size: 16px;
|
| 40 |
-
margin-bottom: 30px;
|
| 41 |
}
|
| 42 |
.output-box {
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
padding: 15px;
|
| 46 |
border-radius: 10px;
|
|
|
|
| 47 |
}
|
| 48 |
""") as demo:
|
| 49 |
|
| 50 |
-
gr.Markdown("<div id='title'
|
| 51 |
-
gr.Markdown("<div id='subtitle'>Enter a topic and see how different LLMs generate creative content.</div>")
|
| 52 |
|
| 53 |
with gr.Row():
|
| 54 |
with gr.Column():
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
gen_btn = gr.Button("β¨ Generate Content")
|
| 58 |
|
| 59 |
with gr.Column():
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
|
| 64 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Lightweight models that work within 16GB RAM
|
| 5 |
models = {
|
| 6 |
+
"π T5-Small": pipeline("text2text-generation", model="t5-small"),
|
| 7 |
+
"π DistilGPT2": pipeline("text-generation", model="distilgpt2"),
|
| 8 |
+
"π DistilBART": pipeline("text2text-generation", model="sshleifer/distilbart-cnn-12-6"),
|
| 9 |
+
"π Pegasus-Tiny": pipeline("text2text-generation", model="google/pegasus-small"),
|
| 10 |
+
"π FLAN-T5-Base": pipeline("text2text-generation", model="google/flan-t5-base")
|
| 11 |
}
|
| 12 |
|
| 13 |
+
# Content generation function
|
| 14 |
+
def generate_content(topic):
|
| 15 |
+
outputs = {}
|
| 16 |
+
for name, model in models.items():
|
| 17 |
+
try:
|
| 18 |
+
if "text-generation" in str(model):
|
| 19 |
+
result = model(topic, max_length=100, do_sample=False)[0]['generated_text']
|
| 20 |
+
else:
|
| 21 |
+
result = model(topic, max_length=100, do_sample=False)[0]['generated_text']
|
| 22 |
+
outputs[name] = result
|
| 23 |
+
except Exception as e:
|
| 24 |
+
outputs[name] = f"Error: {str(e)}"
|
| 25 |
+
return [outputs[name] for name in models.keys()]
|
| 26 |
+
|
| 27 |
+
# Gradio UI
|
| 28 |
+
gr.Theme.set("default")
|
| 29 |
with gr.Blocks(css="""
|
| 30 |
body {
|
| 31 |
+
background-color: #fffde7;
|
| 32 |
}
|
| 33 |
#title {
|
|
|
|
| 34 |
text-align: center;
|
| 35 |
+
font-size: 34px;
|
| 36 |
font-weight: bold;
|
| 37 |
+
color: #8b4513;
|
| 38 |
+
margin-bottom: 20px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
.output-box {
|
| 41 |
+
border: 2px solid #d4af37;
|
| 42 |
+
padding: 10px;
|
|
|
|
| 43 |
border-radius: 10px;
|
| 44 |
+
background-color: #fff8dc;
|
| 45 |
}
|
| 46 |
""") as demo:
|
| 47 |
|
| 48 |
+
gr.Markdown("<div id='title'>π LLM for Content Generation</div>")
|
|
|
|
| 49 |
|
| 50 |
with gr.Row():
|
| 51 |
with gr.Column():
|
| 52 |
+
topic = gr.Textbox(label="Enter your topic", placeholder="e.g. Climate Change Impact on Economy")
|
| 53 |
+
generate_button = gr.Button("Generate Content β¨")
|
|
|
|
| 54 |
|
| 55 |
with gr.Column():
|
| 56 |
+
outputs = [gr.Textbox(label=model, lines=6, elem_classes=["output-box"]) for model in models.keys()]
|
| 57 |
+
|
| 58 |
+
generate_button.click(fn=generate_content, inputs=[topic], outputs=outputs)
|
| 59 |
|
| 60 |
+
gr.Markdown("<center>π‘ Compare outputs from 5 different lightweight LLMs. Fast, efficient, and creative!</center>")
|
| 61 |
|
| 62 |
demo.launch()
|