Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, pipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load the model and tokenizer
|
| 6 |
+
model = "K00B404/DeepQwenScalerPlus"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model)
|
| 8 |
+
|
| 9 |
+
# Initialize the pipeline for text generation
|
| 10 |
+
pipeline = pipeline(
|
| 11 |
+
"text-generation",
|
| 12 |
+
model=model,
|
| 13 |
+
torch_dtype=torch.float16,
|
| 14 |
+
device_map="auto",
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
# Function to interact with the model
|
| 18 |
+
def generate_response(user_message):
|
| 19 |
+
messages = [
|
| 20 |
+
{"role": "system", "content": "You are a reasoning coder and specialize in generating Python scripts"},
|
| 21 |
+
{"role": "user", "content": user_message}
|
| 22 |
+
]
|
| 23 |
+
|
| 24 |
+
# Tokenize the input message
|
| 25 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 26 |
+
|
| 27 |
+
# Get the model's output
|
| 28 |
+
outputs = pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
| 29 |
+
|
| 30 |
+
return outputs[0]["generated_text"]
|
| 31 |
+
|
| 32 |
+
# Gradio interface
|
| 33 |
+
iface = gr.Interface(
|
| 34 |
+
fn=generate_response,
|
| 35 |
+
inputs=gr.Textbox(label="Ask a Question", placeholder="Enter your question here..."),
|
| 36 |
+
outputs=gr.Textbox(label="Generated Response"),
|
| 37 |
+
title="DeepQwenScalerPlus Gradio App",
|
| 38 |
+
description="Interact with the DeepQwenScalerPlus model to get Python script generation responses."
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# Launch the Gradio app
|
| 42 |
+
iface.launch()
|