Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers_js_py import pipeline | |
import asyncio | |
async def main(): | |
""" | |
Main asynchronous function to initialize the sentiment analysis pipeline and launch the Gradio interface. | |
""" | |
try: | |
sentiment_pipeline = await pipeline('sentiment-analysis') | |
async def process(text): | |
""" | |
Asynchronous function to process text and return sentiment analysis results. | |
""" | |
try: | |
result = await sentiment_pipeline(text) | |
return result | |
except Exception as e: | |
print(f"Error processing text: {e}") | |
return {"error": str(e)} | |
demo = gr.Interface(fn=process, inputs="text", outputs="json", title="Sentiment Analysis") | |
demo.launch() | |
except Exception as e: | |
print(f"Error initializing pipeline or interface: {e}") | |
if __name__ == "__main__": | |
asyncio.run(main()) |