LucidMinds3ye commited on
Commit
3b55e60
ยท
verified ยท
1 Parent(s): 26b6853

Create app.py

Browse files

"Initial commit: Added the full Eternal Equation AI Processor".

Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Title and Description for your app
5
+ TITLE = "๐Ÿง  Eternal Equation AI Processor (- = +)"
6
+ DESCRIPTION = """
7
+ Paste your text, choose a processing mode, and see the AI magic happen!
8
+ This demo runs on free CPU hardware, so please be patient for longer texts.
9
+ """
10
+
11
+ # Load your specialist models (The Orchestra) - They load when the Space starts
12
+ sentiment_pipeline = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
13
+ summarize_pipeline = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
14
+
15
+ # Define your processing function (The Conductor)
16
+ def process_text(input_text, mode):
17
+ # Check for empty input
18
+ if not input_text.strip():
19
+ return "โš ๏ธ Please enter some text to process."
20
+
21
+ try:
22
+ if mode == "Sentiment Analysis":
23
+ result = sentiment_pipeline(input_text)
24
+ return f"๐ŸŽฏ **Label:** {result[0]['label']}\n\n๐Ÿ”ฎ **Confidence:** {result[0]['score']:.4f}"
25
+
26
+ elif mode == "Text Summarization":
27
+ # Check if input is long enough
28
+ if len(input_text.split()) < 50:
29
+ return "๐Ÿ“ **Please provide a longer text for summarization (at least 50 words).** This model is designed for articles and paragraphs."
30
+ result = summarize_pipeline(input_text, max_length=130, min_length=30, do_sample=False)
31
+ return f"๐Ÿ“„ **Summary:**\n\n{result[0]['summary_text']}"
32
+
33
+ except Exception as e:
34
+ # This will catch any errors and show a user-friendly message
35
+ return f"โŒ An error occurred while processing your request. Please try again with different text.\n\n(Error: {str(e)})"
36
+
37
+ # Create the Gradio Interface (The Frontend UI)
38
+ demo = gr.Interface(
39
+ fn=process_text, # The function to call
40
+ inputs=[
41
+ gr.Textbox(label="โž– Input Text", placeholder="Paste your text here...", lines=5),
42
+ gr.Radio(choices=["Sentiment Analysis", "Text Summarization"], label="๐ŸŸฐ Processing Mode", value="Sentiment Analysis")
43
+ ],
44
+ outputs=gr.Textbox(label="โž• AI Output", lines=5),
45
+ title=TITLE,
46
+ description=DESCRIPTION,
47
+ examples=[
48
+ ["I am absolutely thrilled with this product! It's everything I hoped for and more.", "Sentiment Analysis"],
49
+ ["""The field of artificial intelligence (AI) has seen unprecedented growth in the last decade. Breakthroughs in machine learning, particularly deep learning, have driven advancements in areas from computer vision to natural language processing. Companies across all sectors are investing heavily in AI research and implementation, hoping to gain a competitive edge. This rapid expansion has also sparked important debates about ethics, bias in algorithms, and the future of work. While the potential benefits are vast, experts urge for careful consideration of the societal impacts to ensure the technology is developed and used responsibly.""", "Text Summarization"]
50
+ ]
51
+ )
52
+
53
+ # Launch the app
54
+ demo.launch()