Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,14 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
def generate_text(
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
interface = gr.Interface(
|
| 13 |
-
fn=generate_text,
|
| 14 |
-
inputs=gr.Textbox(lines=4, placeholder="Enter your text prompt here..."),
|
| 15 |
-
outputs="text",
|
| 16 |
-
title="Text-to-Text Generator AI",
|
| 17 |
-
description="This AI generates text based on your input using a Hugging Face model."
|
| 18 |
-
)
|
| 19 |
|
| 20 |
-
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen1.5-1.8B", trust_remote_code=True)
|
| 6 |
+
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen1.5-1.8B", device_map="auto", trust_remote_code=True)
|
| 7 |
|
| 8 |
+
def generate_text(prompt):
|
| 9 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 10 |
+
outputs = model.generate(**inputs, max_new_tokens=100)
|
| 11 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 12 |
|
| 13 |
+
gr.Interface(fn=generate_text, inputs="text", outputs="text", title="Qwen Text Generator").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
|
|