Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers_js_py import pipeline
|
|
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
async def process(text):
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
demo = gr.Interface(fn=process, inputs="text", outputs="json")
|
|
|
10 |
|
11 |
-
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers_js_py import pipeline
|
3 |
+
import asyncio
|
4 |
|
5 |
+
async def main():
|
6 |
+
"""
|
7 |
+
Main asynchronous function to initialize the sentiment analysis pipeline and launch the Gradio interface.
|
8 |
+
"""
|
9 |
+
try:
|
10 |
+
sentiment_pipeline = await pipeline('sentiment-analysis')
|
11 |
|
12 |
+
async def process(text):
|
13 |
+
"""
|
14 |
+
Asynchronous function to process text and return sentiment analysis results.
|
15 |
+
"""
|
16 |
+
try:
|
17 |
+
result = await sentiment_pipeline(text)
|
18 |
+
return result
|
19 |
+
except Exception as e:
|
20 |
+
print(f"Error processing text: {e}")
|
21 |
+
return {"error": str(e)}
|
22 |
|
23 |
+
demo = gr.Interface(fn=process, inputs="text", outputs="json", title="Sentiment Analysis")
|
24 |
+
demo.launch()
|
25 |
|
26 |
+
except Exception as e:
|
27 |
+
print(f"Error initializing pipeline or interface: {e}")
|
28 |
+
|
29 |
+
if __name__ == "__main__":
|
30 |
+
asyncio.run(main())
|