rviana commited on
Commit
eea1f8d
·
1 Parent(s): 6179462

Fix GRADIO version.

Browse files
Files changed (1) hide show
  1. app.py +14 -6
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
- # Check if GRADIO_SERVER_PORT is set, otherwise use a different port
13
- import os
14
- port = int(os.getenv('GRADIO_SERVER_PORT', 7861))
 
 
15
 
16
- # Launch the Gradio interface on the specified port
17
- iface.launch(server_port=port)
 
 
 
 
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.')