Joe7oo7 commited on
Commit
43c7970
·
verified ·
1 Parent(s): 8cf11ad

Create gradio_app.py

Browse files
Files changed (1) hide show
  1. gradio_app.py +25 -0
gradio_app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Step 1: Load the pre-trained model
5
+ # You can choose any suitable conversational model from the Hugging Face Model Hub
6
+ chatbot = pipeline("conversational", model="microsoft/DialoGPT-small")
7
+
8
+ # Step 2: Define the function that will process user input and return the model's response
9
+ def respond(input_text):
10
+ conversation = chatbot([input_text])
11
+ return conversation[0]["generated_text"]
12
+
13
+ # Step 3: Create a Gradio interface
14
+ # This interface will take text input from the user and display the chatbot's response
15
+ iface = gr.Interface(
16
+ fn=respond, # The function to call when the user submits input
17
+ inputs="text", # The type of input (text)
18
+ outputs="text", # The type of output (text)
19
+ title="HugChat - Your AI Chatbot", # The title of your chatbot
20
+ description="Chat with an AI-powered bot based on a pre-trained model." # A short description
21
+ )
22
+
23
+ # Step 4: Launch the interface
24
+ if __name__ == "__main__":
25
+ iface.launch()