Update app.py
Browse files
app.py
CHANGED
|
@@ -12,19 +12,30 @@ auth = tweepy.OAuth1UserHandler(api_key, api_secret, access_token, access_token_
|
|
| 12 |
api = tweepy.API(auth)
|
| 13 |
from gradio_client import Client
|
| 14 |
|
| 15 |
-
client
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
api_name="/predict"
|
| 19 |
-
)
|
| 20 |
-
print(result)
|
| 21 |
-
cut_text = result[:160]
|
| 22 |
-
print(cut_text)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
#
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
api = tweepy.API(auth)
|
| 13 |
from gradio_client import Client
|
| 14 |
|
| 15 |
+
# Assuming you have a Gradio client setup for your model
|
| 16 |
+
from gradio_client import Client
|
| 17 |
+
model_client = Client("https://tonic-surerag.hf.space/--replicas/m666j/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
def generate_and_tweet(query):
|
| 20 |
+
# Generate text based on the user's query
|
| 21 |
+
result = model_client.predict(query, api_name="/predict")
|
| 22 |
+
|
| 23 |
+
# Cut the text to fit Twitter's character limit if necessary
|
| 24 |
+
tweet_text = result[:280] # Twitter's character limit is 280
|
| 25 |
+
|
| 26 |
+
# Post the generated text to Twitter
|
| 27 |
+
response = clientw.create_tweet(text=tweet_text)
|
| 28 |
+
|
| 29 |
+
# Return the tweet URL or confirmation
|
| 30 |
+
tweet_id = response.data['id']
|
| 31 |
+
tweet_url = f"https://twitter.com/user/status/{tweet_id}"
|
| 32 |
+
return f"Tweeted successfully! Here's the URL: {tweet_url}"
|
| 33 |
|
| 34 |
+
iface = gr.Interface(
|
| 35 |
+
fn=generate_and_tweet,
|
| 36 |
+
inputs="text",
|
| 37 |
+
outputs="text",
|
| 38 |
+
title="Generate and Tweet",
|
| 39 |
+
description="Enter your query to generate a Twitter post about it and automatically tweet it."
|
| 40 |
+
)
|
| 41 |
+
iface.launch()
|