Spaces:
Runtime error
Runtime error
Download app.py from GenAiPA/First_chatbot: direct link, hf CLI and curl.
- Browser
- Download file 744 Bytes
-
https://huggingface.co/spaces/GenAiPA/First_chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/GenAiPA/First_chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/GenAiPA/First_chatbot/resolve/main/app.py
744 Bytes
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| import os | |
| # Retrieve the token from an environment variable | |
| token = os.getenv("PA_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() |