AnotherIndian commited on
Commit
31012b0
verified
1 Parent(s): d82d9f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -10
app.py CHANGED
@@ -1,13 +1,47 @@
1
- import gradio as gr
2
- from transformers import pipeline
 
3
 
4
- # Cargar el modelo de generaci贸n de texto
5
- generator = pipeline("text-generation", model="EleutherAI/gpt-neo-125M") # Puedes elegir otro modelo de Hugging Face
 
 
 
 
 
 
 
 
6
 
7
- # Funci贸n para generar el tweet
8
- def generate_tweet(input_text):
9
- return generator(input_text, max_length=50)[0]['generated_text']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- # Crear interfaz Gradio para generar tweets
12
- demo = gr.Interface(fn=generate_tweet, inputs="text", outputs="text")
13
- demo.launch()
 
1
+ import tweepy # Import the tweepy library to interact with Twitter API
2
+ import openai # Import OpenAI API for language generation
3
+ import time # Import time library to control tweet timing
4
 
5
+ # Authentication for Twitter API
6
+ def authenticate_twitter():
7
+ auth = tweepy.OAuth1UserHandler(
8
+ consumer_key='RGo5d1VySEtOd2VXX2p3MWEzWVU6MTpjaQ',
9
+ consumer_secret='6yww6Q1YzERRPc4ypEXcTcK1J3ET_rKK7i88z9KDKiNoA7PpuC',
10
+ access_token='1862985406393823232-gnHrZgwXsU3Y4822LfxyXp3ZMnDDNj',
11
+ access_token_secret='lR6rNMOI6UtVmqtS6Nsa5lXR7k9f67qQ5FF6nOChdhjdU'
12
+ )
13
+ api = tweepy.API(auth)
14
+ return api
15
 
16
+ # Authentication for OpenAI API
17
+ def authenticate_openai():
18
+ openai.api_key = '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'
19
+
20
+ # Function to generate a tweet using GPT-3
21
+ def generate_tweet():
22
+ response = openai.Completion.create(
23
+ engine="text-davinci-003", # You can choose the model to use
24
+ prompt="Create a tweet in the style of a humorous AI agent, keeping it casual and engaging.",
25
+ max_tokens=50
26
+ )
27
+ tweet = response.choices[0].text.strip()
28
+ return tweet
29
+
30
+ # Function to send the tweet to Twitter
31
+ def send_tweet(api, tweet):
32
+ api.update_status(tweet) # Send the generated tweet
33
+
34
+ # Main function to control the tweet posting loop
35
+ def main():
36
+ twitter_api = authenticate_twitter() # Get Twitter API instance
37
+ authenticate_openai() # Authenticate OpenAI API
38
+
39
+ while True:
40
+ tweet = generate_tweet() # Generate a new tweet
41
+ print(f"Tweeting: {tweet}")
42
+ send_tweet(twitter_api, tweet) # Send the tweet to Twitter
43
+ time.sleep(1800) # Wait for 30 minutes before posting the next tweet
44
+
45
+ if __name__ == "__main__":
46
+ main() # Start the program
47