Patrik Stano commited on
Commit
a6319a1
·
1 Parent(s): 66750cf

Add application file

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the Hugging Face model
5
+ # Replace 'your-username/your-model-name' with the actual path to your Hugging Face model
6
+ model_path = "patrixtano/mt5-small-anaphora_czech_6e"
7
+ model_pipeline = pipeline("text2text-generation", model=model_path)
8
+
9
+ def predict(text_input):
10
+ """
11
+ Generate a prediction for the given input text using the Hugging Face model.
12
+ """
13
+ try:
14
+ result = model_pipeline(text_input)
15
+ # Extract and return the generated text
16
+ return result[0]["generated_text"]
17
+ except Exception as e:
18
+ return f"Error: {str(e)}"
19
+
20
+ # Define the Gradio interface
21
+ interface = gr.Interface(
22
+ fn=predict,
23
+ inputs=gr.Textbox(lines=5, label="Input Text"),
24
+ outputs=gr.Textbox(label="Model Output"),
25
+ title="Hugging Face Model Demo",
26
+ description="Enter text into the input box, and the model will generate an output based on your input.",
27
+ theme="default"
28
+ )
29
+
30
+ # Launch the Gradio app
31
+ if __name__ == "__main__":
32
+ interface.launch()