Tonic commited on
Commit
1623793
·
verified ·
1 Parent(s): b2af2fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -18,17 +18,24 @@ from gradio_client import Client
18
  from gradio_client import Client
19
  model_client = Client("https://tonic-surerag.hf.space/--replicas/m666j/")
20
 
21
- def generate_and_tweet(query):
22
  # Generate text based on the user's query
23
- result = model_client.predict(query, api_name="/predict")
24
 
25
- # Cut the text to fit Twitter's character limit if necessary
26
- tweet_text = result[:180] # Twitter's character limit is 280
 
 
 
 
 
 
27
 
28
- # Post the generated text to Twitter
29
- response = clientw.create_tweet(text=tweet_text)
30
 
31
- # Return the tweet URL or confirmation
 
32
  tweet_id = response.data['id']
33
  tweet_url = f"https://twitter.com/user/status/{tweet_id}"
34
  return f"Tweeted successfully! Here's the URL: {tweet_url}"
 
18
  from gradio_client import Client
19
  model_client = Client("https://tonic-surerag.hf.space/--replicas/m666j/")
20
 
21
+ def generate_and_tweet(query):def generate_and_tweet(query):
22
  # Generate text based on the user's query
23
+ response = model_client.predict(query, api_name="/predict")
24
 
25
+ # Assuming the response is a dictionary and the generated text is under a key, e.g., 'generated_text'
26
+ # Adjust the key as per your model's response structure
27
+ if isinstance(response, dict) and 'generated_text' in response:
28
+ tweet_text = response['generated_text']
29
+ elif isinstance(response, str): # Direct string response
30
+ tweet_text = response
31
+ else:
32
+ return "Error: The model's response was not in the expected format."
33
 
34
+ # Ensure the tweet text is a string and trim it to Twitter's character limit
35
+ tweet_text = str(tweet_text)[:280] # Twitter's character limit is 280
36
 
37
+ tweet_text = result[:180] # Twitter's character limit is 280
38
+ response = clientw.create_tweet(text=tweet_text)
39
  tweet_id = response.data['id']
40
  tweet_url = f"https://twitter.com/user/status/{tweet_id}"
41
  return f"Tweeted successfully! Here's the URL: {tweet_url}"