Spaces:
Sleeping
Sleeping
snugboo
commited on
Commit
·
2a48d1e
1
Parent(s):
4975216
Add app.py and requirements.txt for Qwen model
Browse files- app.py +30 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Load tokenizer and model
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("AiCloser/Qwen2.5-32B-AGI")
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(
|
7 |
+
"AiCloser/Qwen2.5-32B-AGI",
|
8 |
+
device_map="auto",
|
9 |
+
torch_dtype="auto",
|
10 |
+
resume_download=True # Allow resumable downloads
|
11 |
+
)
|
12 |
+
|
13 |
+
# Define text generation function
|
14 |
+
def generate_text(prompt):
|
15 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
16 |
+
outputs = model.generate(**inputs, max_length=200)
|
17 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
18 |
+
|
19 |
+
# Create Gradio interface
|
20 |
+
interface = gr.Interface(
|
21 |
+
fn=generate_text,
|
22 |
+
inputs="text",
|
23 |
+
outputs="text",
|
24 |
+
title="Qwen 2.5-32B Text Generator",
|
25 |
+
description="Generate text using the Qwen2.5-32B-AGI model. Enter a prompt below."
|
26 |
+
)
|
27 |
+
|
28 |
+
# Launch interface
|
29 |
+
if __name__ == "__main__":
|
30 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
gradio
|
3 |
+
accelerate
|
4 |
+
torch
|