Spaces:
Runtime error
Runtime error
File size: 641 Bytes
d097592 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import gradio as gr
from transformers import pipeline
# Load a fast, lightweight open-source model
pipe = pipeline("text-generation", model="Qwen/Qwen2.5-0.5B-Instruct")
def generate_response(prompt):
messages = [{"role": "user", "content": prompt}]
output = pipe(messages, max_new_tokens=200)
return output[0]["generated_text"][-1]["content"]
# Create the Gradio web app and API
demo = gr.Interface(
fn=generate_response,
inputs=gr.Textbox(
lines=3, placeholder="Enter your prompt here...", label="Prompt"
),
outputs=gr.Textbox(label="Response"),
title="Open-Source Model API",
)
demo.launch()
|