Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
|
4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
+
|
6 |
+
# Load model and tokenizer directly from Hugging Face Hub
|
7 |
+
model = AutoModelForCausalLM.from_pretrained("Manasa1/gpt-finetuned-tweets")
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained("Manasa1/gpt-finetuned-tweets")
|
9 |
+
|
10 |
+
|
11 |
+
# Define the function to generate tweets
|
12 |
+
def generate_tweet():
|
13 |
+
prompt = "Generate a tweet that reflects the personality in the fine-tuned dataset:"
|
14 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512)
|
15 |
+
outputs = model.generate(
|
16 |
+
inputs["input_ids"],
|
17 |
+
max_length=280,
|
18 |
+
num_return_sequences=1,
|
19 |
+
top_p=0.9,
|
20 |
+
temperature=0.7
|
21 |
+
)
|
22 |
+
generated_tweet = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
23 |
+
return generated_tweet.strip()
|
24 |
+
|
25 |
+
# Gradio Interface
|
26 |
+
with gr.Blocks() as app:
|
27 |
+
gr.Markdown("# AI Tweet Generator")
|
28 |
+
gr.Markdown("Click the button below to generate a tweet reflecting the fine-tuned personality.")
|
29 |
+
generate_button = gr.Button("Generate")
|
30 |
+
output_box = gr.Textbox(label="Generated Tweet")
|
31 |
+
|
32 |
+
generate_button.click(generate_tweet, inputs=None, outputs=output_box)
|
33 |
+
|
34 |
+
# Launch the app locally
|
35 |
+
app.launch()
|