[yesha vyas] commited on
Commit
4d41123
·
1 Parent(s): f0fb5d6

Basic demo

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
+ import gradio as gr
3
+
4
+ # Load the fine-tuned model and tokenizer from Hugging Face
5
+ model_name = "yeshavyas27/moondream-ft"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForSequenceClassification.from_pretrained(model_name, trust_remote_code=True)
8
+
9
+ # Define the inference function
10
+ def predict(input_text):
11
+ inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True)
12
+ outputs = model(**inputs)
13
+ predictions = outputs.logits.argmax(dim=-1)
14
+ return predictions.item()
15
+
16
+ # Set up the Gradio interface
17
+ iface = gr.Interface(
18
+ fn=predict,
19
+ inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
20
+ outputs="text",
21
+ title="Moondream Model Inference",
22
+ description="Enter some text to get predictions from the fine-tuned Moondream model."
23
+ )
24
+
25
+ # Run the app
26
+ if __name__ == "__main__":
27
+ iface.launch()