Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
-
import os
|
4 |
-
|
5 |
-
# Use the Hugging Face Inference API
|
6 |
-
client = InferenceClient("01-ai/Yi-Coder-9B-Chat")
|
7 |
-
|
8 |
-
# Load the dataset
|
9 |
-
with open("dataset.txt", "r", encoding='utf-8') as f:
|
10 |
-
dataset = f.read()
|
11 |
-
|
12 |
-
def chatbot_response(user_input):
|
13 |
-
# Combine the dataset and user input
|
14 |
-
prompt = f"""Based on the following dataset, answer the user's question:
|
15 |
-
|
16 |
-
Dataset:
|
17 |
-
{dataset}
|
18 |
-
|
19 |
-
User question: {user_input}
|
20 |
-
|
21 |
-
Answer:"""
|
22 |
-
|
23 |
-
# Use the Inference API to generate a response
|
24 |
-
response = client.text_generation(prompt, max_new_tokens=500, temperature=0.7)
|
25 |
-
return response
|
26 |
-
|
27 |
-
# Set up the Gradio interface
|
28 |
-
with gr.Blocks() as chat_interface:
|
29 |
-
gr.Markdown("# CPSL Chatbot")
|
30 |
-
chat_history = gr.Chatbot()
|
31 |
-
user_input = gr.Textbox(label="Your Message:")
|
32 |
-
send_button = gr.Button("Send")
|
33 |
-
|
34 |
-
def interact(user_message, history):
|
35 |
-
bot_reply = chatbot_response(user_message)
|
36 |
-
history.append((user_message, bot_reply))
|
37 |
-
return history, history
|
38 |
-
|
39 |
-
send_button.click(interact, inputs=[user_input, chat_history], outputs=[chat_history, chat_history])
|
40 |
-
|
41 |
-
# Launch the interface
|
42 |
-
if __name__ == "__main__":
|
43 |
-
chat_interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|