SivaMallikarjun commited on
Commit
b8b150c
·
verified ·
1 Parent(s): 76aeebf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from model import SimpleMultilingualClassifier # Import your model
4
+
5
+ # --- Configuration ---
6
+ embedding_files = {
7
+ 'en': 'fasttext_embeddings/cc.en.100.bin',
8
+ 'fr': 'fasttext_embeddings/cc.fr.100.bin'
9
+ # Add more languages as needed
10
+ }
11
+ num_classes = 3 # Replace with the actual number of classes
12
+ class_labels = ["positive", "negative", "neutral"] # Replace with your actual class labels
13
+
14
+ # Load the model
15
+ try:
16
+ model = SimpleMultilingualClassifier(embedding_files, num_classes)
17
+ # In a real scenario, you would load trained weights here:
18
+ # model.load_state_dict(torch.load('path/to/your/trained_weights.pth'))
19
+ model.eval()
20
+ except Exception as e:
21
+ print(f"Error loading model: {e}")
22
+ model = None
23
+
24
+ def classify_text(text, language):
25
+ if model:
26
+ try:
27
+ prediction = model.predict(text, language, class_labels)
28
+ return prediction
29
+ except ValueError as e:
30
+ return str(e)
31
+ else:
32
+ return "Model not loaded."
33
+
34
+ iface = gr.Interface(
35
+ fn=classify_text,
36
+ inputs=[
37
+ gr.Textbox(label="Enter text"),
38
+ gr.Dropdown(choices=list(embedding_files.keys()), label="Language")
39
+ ],
40
+ outputs=gr.Textbox(label="Prediction"),
41
+ title="Simple Multilingual Text Classifier",
42
+ description="A basic multilingual text classifier using FastText embeddings.",
43
+ )
44
+
45
+ iface.launch()