Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,44 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
model = AutoModelForCausalLM.from_pretrained(
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
model.
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
|
4 |
+
# Load pre-trained model (or fine-tuned model)
|
5 |
+
model_name = "Manasa1/GPT_Finetuned_tweets" # Replace with the fine-tuned model name
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Function to generate tweets
|
10 |
+
def generate_tweet(input_text):
|
11 |
+
prompt = ("You are a tech-savvy, forward-thinking individual with a deep understanding of technology, innovation, and cultural trends. "
|
12 |
+
"Craft a tweet that reflects insightful commentary, wit, or actionable advice based on the following idea: \"{}\". "
|
13 |
+
"Ensure the response is concise, engaging, and suitable for a diverse audience on social media. "
|
14 |
+
"Incorporate elements of thought leadership, futuristic perspectives, and practical wisdom where appropriate.").format(input_text)
|
15 |
+
|
16 |
+
inputs = tokenizer(prompt, return_tensors="pt", max_length=512, truncation=True)
|
17 |
+
outputs = model.generate(inputs['input_ids'], max_length=280, num_return_sequences=1, top_p=0.95, top_k=50)
|
18 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
19 |
+
|
20 |
+
# Extract the tweet text (exclude prompt if included)
|
21 |
+
return generated_text.replace(prompt, "").strip()
|
22 |
+
|
23 |
+
# Gradio interface
|
24 |
+
def main():
|
25 |
+
with gr.Blocks() as interface:
|
26 |
+
gr.Markdown("""
|
27 |
+
# Tweet Generator
|
28 |
+
Enter a topic or idea, and the AI will craft a tweet inspired by innovative, philosophical, and tech-savvy thought leadership.
|
29 |
+
""")
|
30 |
+
|
31 |
+
with gr.Row():
|
32 |
+
input_text = gr.Textbox(label="Enter your idea or topic:")
|
33 |
+
output_tweet = gr.Textbox(label="Generated Tweet:", interactive=False)
|
34 |
+
|
35 |
+
generate_button = gr.Button("Generate Tweet")
|
36 |
+
|
37 |
+
generate_button.click(generate_tweet, inputs=[input_text], outputs=[output_tweet])
|
38 |
+
|
39 |
+
return interface
|
40 |
+
|
41 |
+
# Run Gradio app
|
42 |
+
if __name__ == "__main__":
|
43 |
+
app = main()
|
44 |
+
app.launch()
|