Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,31 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
|
|
|
|
|
|
| 10 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
pipe = pipeline("text-generation", model="google/gemma-3-1b-it", torch_dtype=torch.bfloat16)
|
| 6 |
+
|
| 7 |
+
messages = [
|
| 8 |
+
[
|
| 9 |
+
{
|
| 10 |
+
"role": "system",
|
| 11 |
+
"content": [{"type": "text", "text": "You are a helpful assistant."}],
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"role": "user",
|
| 15 |
+
"content": [{"type": "text", "text": "Tell me some of the most important part in a motorcycle"}],
|
| 16 |
+
},
|
| 17 |
+
],
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
def predict():
|
| 21 |
+
output = pipe(messages, max_new_tokens=500)
|
| 22 |
+
return str(output)
|
| 23 |
+
|
| 24 |
+
with gr.Blocks() as demo:
|
| 25 |
+
gr.Markdown("# AI Output")
|
| 26 |
+
output_box = gr.Textbox(label="Generated Output", lines=10)
|
| 27 |
+
generate_btn = gr.Button("Generate")
|
| 28 |
|
| 29 |
+
generate_btn.click(fn=predict, outputs=output_box)
|
| 30 |
+
|
| 31 |
demo.launch()
|