Spaces:
Sleeping
Sleeping
Fix GRADIO version.
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
|
|
3 |
|
4 |
# Load the pre-trained sentiment-analysis pipeline
|
5 |
classifier = pipeline('sentiment-analysis')
|
@@ -9,13 +11,19 @@ def classify_text(text):
|
|
9 |
result = classifier(text)[0]
|
10 |
return f"{result['label']} with score {result['score']}"
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
|
16 |
-
#
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
|
19 |
# Streamlit code
|
20 |
st.title('IMDb Sentiment Analysis')
|
21 |
-
st.write('This project performs sentiment analysis on IMDb movie reviews using Streamlit.')
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
import streamlit as st
|
4 |
+
import socket
|
5 |
|
6 |
# Load the pre-trained sentiment-analysis pipeline
|
7 |
classifier = pipeline('sentiment-analysis')
|
|
|
11 |
result = classifier(text)[0]
|
12 |
return f"{result['label']} with score {result['score']}"
|
13 |
|
14 |
+
# Function to find an available port
|
15 |
+
def find_free_port():
|
16 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
17 |
+
s.bind(('', 0))
|
18 |
+
return s.getsockname()[1]
|
19 |
|
20 |
+
# Find an available port
|
21 |
+
port = find_free_port()
|
22 |
+
|
23 |
+
# Launch the Gradio interface on the dynamically found port
|
24 |
+
iface = gr.Interface(fn=classify_text, inputs="text", outputs="text")
|
25 |
+
iface.launch(server_port=port, share=True)
|
26 |
|
27 |
# Streamlit code
|
28 |
st.title('IMDb Sentiment Analysis')
|
29 |
+
st.write('This project performs sentiment analysis on IMDb movie reviews using Streamlit.')
|