Jack_Clone / app.py
Manasa1's picture
Upload 4 files
559513f verified
raw
history blame
2.7 kB
import gradio as gr
import os
from tweet_analyzer import TweetDatasetProcessor
from dotenv import load_dotenv
load_dotenv()
class TwitterCloneApp:
def __init__(self):
self.processor = None
def process_upload(self, file):
"""Process uploaded PDF file and analyze personality"""
try:
self.processor = TweetDatasetProcessor()
text = self.processor.extract_text_from_pdf(file.name)
df = self.processor.process_pdf_content(text)
personality_analysis = self.processor.analyze_personality()
return f"Processed {len(df)} tweets\n\nPersonality Analysis:\n{personality_analysis}"
except Exception as e:
return f"Error processing file: {str(e)}"
def generate_tweet(self, context):
"""Generate a new tweet based on the analyzed personality"""
if not self.processor:
return "Please upload and analyze a dataset first."
try:
tweet = self.processor.generate_tweet(context)
return tweet
except Exception as e:
return f"Error generating tweet: {str(e)}"
def create_interface(self):
"""Create the Gradio interface"""
with gr.Blocks(title="Twitter Personality Cloner") as interface:
gr.Markdown("# Twitter Personality Cloner")
gr.Markdown("Upload a PDF file containing tweets to analyze the author's personality and generate new tweets in their style.")
with gr.Tab("Analyze Personality"):
file_input = gr.File(label="Upload PDF Dataset", file_types=[".pdf"])
analyze_button = gr.Button("Analyze Dataset")
analysis_output = gr.Textbox(label="Analysis Results", lines=10)
analyze_button.click(
fn=self.process_upload,
inputs=file_input,
outputs=analysis_output
)
with gr.Tab("Generate Tweets"):
context_input = gr.Textbox(label="Context (optional)", placeholder="Enter topic or context for the tweet")
generate_button = gr.Button("Generate Tweet")
tweet_output = gr.Textbox(label="Generated Tweet")
generate_button.click(
fn=self.generate_tweet,
inputs=context_input,
outputs=tweet_output
)
return interface
def main():
app = TwitterCloneApp()
interface = app.create_interface()
interface.launch(share=True)
if __name__ == "__main__":
main()