decodingdatascience commited on
Commit
f84183c
1 Parent(s): 2fd5a0e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+ import os
4
+
5
+ # Retrieve the token from an environment variable
6
+ token = os.getenv("HF_TOKEN")
7
+ client = InferenceClient(model="gpt2", token=token)
8
+
9
+ def generate_response(prompt):
10
+ response = client.text_generation(prompt)
11
+ return response
12
+
13
+ with gr.Blocks() as demo:
14
+ gr.Markdown("<h1 style='text-align: center;'>Your First AI Chatbot</h1>")
15
+
16
+ # Input components
17
+ msg = gr.Textbox(label="Your Question")
18
+
19
+ # Output component
20
+ output = gr.Textbox(label="AI response")
21
+
22
+ # Button to trigger generation
23
+ submit_btn = gr.Button("Submit")
24
+
25
+ # Link the button to the function
26
+ submit_btn.click(generate_response, inputs=msg, outputs=output)
27
+
28
+ demo.launch()