Spaces:
Sleeping
Sleeping
Update Gradio app with multiple files
Browse files
README.md
CHANGED
|
@@ -7,8 +7,6 @@ sdk: gradio
|
|
| 7 |
sdk_version: 4.44.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
tags:
|
| 11 |
-
- anycoder
|
| 12 |
---
|
| 13 |
|
| 14 |
# AI Chatbot with Hugging Face Model
|
|
|
|
| 7 |
sdk_version: 4.44.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
# AI Chatbot with Hugging Face Model
|
app.py
CHANGED
|
@@ -5,28 +5,29 @@ import os
|
|
| 5 |
# Load the conversational model with HF token support
|
| 6 |
# Using DialoGPT-medium for a larger, more capable chatbot
|
| 7 |
token = os.getenv('HF_TOKEN')
|
| 8 |
-
chatbot_model = pipeline("
|
| 9 |
|
| 10 |
def chat(message, history):
|
| 11 |
# Build conversation string from history
|
| 12 |
conversation_text = ""
|
| 13 |
for user_msg, bot_msg in history:
|
| 14 |
if user_msg:
|
| 15 |
-
conversation_text += f"
|
| 16 |
if bot_msg:
|
| 17 |
-
conversation_text += f"
|
| 18 |
|
| 19 |
# Add current user message
|
| 20 |
-
conversation_text += f"
|
| 21 |
|
| 22 |
# Generate response
|
| 23 |
-
result = chatbot_model(conversation_text)
|
| 24 |
|
| 25 |
-
# Extract the response
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
return response
|
| 32 |
|
|
|
|
| 5 |
# Load the conversational model with HF token support
|
| 6 |
# Using DialoGPT-medium for a larger, more capable chatbot
|
| 7 |
token = os.getenv('HF_TOKEN')
|
| 8 |
+
chatbot_model = pipeline("text-generation", model="microsoft/DialoGPT-medium", token=token)
|
| 9 |
|
| 10 |
def chat(message, history):
|
| 11 |
# Build conversation string from history
|
| 12 |
conversation_text = ""
|
| 13 |
for user_msg, bot_msg in history:
|
| 14 |
if user_msg:
|
| 15 |
+
conversation_text += f"@@PADDING@@ {user_msg} @@PADDING@@ "
|
| 16 |
if bot_msg:
|
| 17 |
+
conversation_text += f"{bot_msg} @@PADDING@@ "
|
| 18 |
|
| 19 |
# Add current user message
|
| 20 |
+
conversation_text += f"@@PADDING@@ {message} @@PADDING@@ "
|
| 21 |
|
| 22 |
# Generate response
|
| 23 |
+
result = chatbot_model(conversation_text, max_length=1000, num_return_sequences=1, temperature=0.8, do_sample=True, pad_token_id=50256)
|
| 24 |
|
| 25 |
+
# Extract the response
|
| 26 |
+
generated_text = result[0]['generated_text']
|
| 27 |
+
|
| 28 |
+
# Split by padding and take the last part as response
|
| 29 |
+
parts = generated_text.split("@@PADDING@@")
|
| 30 |
+
response = parts[-1].strip() if parts else generated_text.strip()
|
| 31 |
|
| 32 |
return response
|
| 33 |
|