Doubleupai commited on
Commit
051c36b
·
verified ·
1 Parent(s): 374d41f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ # Load the model and tokenizer
5
+ model_name = "sambanovasystems/SambaNova-Qwen2.5-Coder-Artifacts"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
+
9
+ def generate_text(prompt):
10
+ # Generate text using the model
11
+ inputs = tokenizer.encode(prompt, return_tensors="pt")
12
+ outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
13
+ text = tokenizer.decode(outputs[0], skip_special_tokens=True)
14
+ return text
15
+
16
+ # Build the Gradio interface
17
+ with gr.Blocks() as demo:
18
+ gr.Markdown("<h1 style='text-align: center;'>AI Text Generator</h1>")
19
+ with gr.Row():
20
+ with gr.Column():
21
+ user_input = gr.Textbox(label="Input Prompt", placeholder="Enter your prompt here...")
22
+ generate_btn = gr.Button("Generate Text")
23
+ with gr.Column():
24
+ output_text = gr.Textbox(label="Generated Text", readonly=True)
25
+ generate_btn.click(generate_text, inputs=user_input, outputs=output_text)
26
+
27
+ # Launch the app
28
+ demo.launch(share=True, theme="macos", css=".gradio-container {background-color: #f0f0f0;}")