Tonic commited on
Commit
5697929
·
verified ·
1 Parent(s): 5be3b07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -14
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 = Client("https://tonic-surerag.hf.space/--replicas/m666j/")
16
- result = client.predict(
17
- "write a twitter post about marketing", # str in 'User Input' Textbox component
18
- api_name="/predict"
19
- )
20
- print(result)
21
- cut_text = result[:160]
22
- print(cut_text)
23
 
24
- clientw.create_tweet(text =result)
25
- # user_name = "@khaym2002"
26
- # tweet_id = "troll"
 
 
 
 
 
 
 
 
 
 
 
27
 
28
- # # Search for replies to the tweet
29
- # replies = tweepy.Cursor(api.search, q=f"to:{user_name}", since_id=tweet_id, tweet_mode="extended").items()
30
- # print(replies)
 
 
 
 
 
 
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()