Spaces:
Sleeping
Sleeping
Stanford-TH
commited on
Commit
•
c33019a
1
Parent(s):
8630f18
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the genre prediction model as a pipeline
|
5 |
+
pipe = pipeline(model="Stanford-TH/GenrePrediction", trust_remote_code=True)
|
6 |
+
|
7 |
+
def classify_movie_genre(description):
|
8 |
+
# Get predictions using the pipeline
|
9 |
+
predictions = pipe(description)
|
10 |
+
|
11 |
+
# Format the predictions to match Gradio's output expectations
|
12 |
+
formatted_predictions = {genre: score for genre, score in predictions}
|
13 |
+
return formatted_predictions
|
14 |
+
|
15 |
+
# Define the Gradio interface
|
16 |
+
iface = gr.Interface(
|
17 |
+
fn=classify_movie_genre,
|
18 |
+
inputs="text",
|
19 |
+
outputs=gr.outputs.Label(num_top_classes=5)
|
20 |
+
)
|
21 |
+
|
22 |
+
# Launch the Gradio interface
|
23 |
+
iface.launch(inline=False)
|