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