Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import os
|
|
2 |
import gradio as gr
|
3 |
from huggingface_hub import InferenceClient
|
4 |
|
5 |
-
|
6 |
# Configuration
|
7 |
MODEL_NAME = "EleutherAI/gpt-neo-125M" # A relatively small model
|
8 |
HF_API_TOKEN = os.environ.get("HF_API_TOKEN", "") # Your Hugging Face API token
|
@@ -23,6 +22,33 @@ if HF_API_TOKEN:
|
|
23 |
else:
|
24 |
print("Warning: HF_API_TOKEN not set. Using limited functionality.")
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
# For demonstration purposes, we'll use a simpler model approach
|
27 |
# that doesn't require an API key but still provides responses
|
28 |
def get_ai_response(message):
|
|
|
2 |
import gradio as gr
|
3 |
from huggingface_hub import InferenceClient
|
4 |
|
|
|
5 |
# Configuration
|
6 |
MODEL_NAME = "EleutherAI/gpt-neo-125M" # A relatively small model
|
7 |
HF_API_TOKEN = os.environ.get("HF_API_TOKEN", "") # Your Hugging Face API token
|
|
|
22 |
else:
|
23 |
print("Warning: HF_API_TOKEN not set. Using limited functionality.")
|
24 |
|
25 |
+
def generate_response(user_input):
|
26 |
+
"""Generate a response from the model based on user input"""
|
27 |
+
if not user_input.strip():
|
28 |
+
return "Please enter a message to get a response from NORTHERN_AI."
|
29 |
+
|
30 |
+
prompt = f"{SYSTEM_PROMPT}\n\nUser: {user_input}\nNORTHERN_AI:"
|
31 |
+
|
32 |
+
try:
|
33 |
+
if client:
|
34 |
+
# Use Hugging Face's Inference API
|
35 |
+
response = client.text_generation(
|
36 |
+
prompt,
|
37 |
+
model=MODEL_NAME,
|
38 |
+
max_new_tokens=150,
|
39 |
+
temperature=0.7,
|
40 |
+
top_p=0.95,
|
41 |
+
repetition_penalty=1.1
|
42 |
+
)
|
43 |
+
# Extract just the assistant's response
|
44 |
+
result = response.split("NORTHERN_AI:")[-1].strip()
|
45 |
+
return result
|
46 |
+
else:
|
47 |
+
return "AI service is currently unavailable. Please check your API token configuration."
|
48 |
+
except Exception as e:
|
49 |
+
print(f"Error generating response: {e}")
|
50 |
+
return f"Sorry, I encountered an error while generating a response. Please try again later."
|
51 |
+
|
52 |
# For demonstration purposes, we'll use a simpler model approach
|
53 |
# that doesn't require an API key but still provides responses
|
54 |
def get_ai_response(message):
|