AdityaShingote commited on
Commit
88301ec
1 Parent(s): be231c6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+
4
+ # Load the model and tokenizer
5
+ model_name = "Qwen/Qwen1.5-7B"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
+
9
+ def generate_article(topic):
10
+ inputs = tokenizer(f"Generate article for the NY times tweet {topic}", return_tensors="pt")
11
+ outputs = model.generate(inputs['input_ids'], max_new_tokens=512, temperature=0.5)
12
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
13
+
14
+ # Create the Gradio interface
15
+ iface = gr.Interface(
16
+ fn=generate_article,
17
+ inputs="text",
18
+ outputs="text",
19
+ title="Article Generator",
20
+ description="Generate an article for a given topic."
21
+ )
22
+
23
+ # Launch the Gradio app
24
+ iface.launch()