Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,59 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import requests
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
"Authorization": f"Bearer {API_TOKEN}",
|
| 12 |
-
"Content-Type": "application/json",
|
| 13 |
-
}
|
| 14 |
-
payload = {
|
| 15 |
-
"inputs": user_input,
|
| 16 |
-
"parameters": {
|
| 17 |
-
"max_length": 100,
|
| 18 |
-
"temperature": 0.7,
|
| 19 |
-
"top_k": 50,
|
| 20 |
-
},
|
| 21 |
-
"options": {"wait_for_model": True},
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
response = requests.post(MODEL_URL, headers=headers, json=payload)
|
| 25 |
-
|
| 26 |
-
if response.status_code == 200:
|
| 27 |
-
result = response.json()
|
| 28 |
-
if result and isinstance(result, list):
|
| 29 |
-
return result[0].get("generated_text", "No response received.")
|
| 30 |
-
else:
|
| 31 |
-
return f"Error {response.status_code}: {response.text}"
|
| 32 |
-
|
| 33 |
-
return "An error occurred while generating a response."
|
| 34 |
-
|
| 35 |
-
# Gradio Interface
|
| 36 |
-
def chatbot(user_message):
|
| 37 |
-
# Add a system message for context
|
| 38 |
-
system_message = "You are a helpful assistant using the Llama-3.3-70B model. Respond thoughtfully."
|
| 39 |
-
full_input = f"{system_message}\nUser: {user_message}\nAssistant:"
|
| 40 |
-
return chat_with_model(full_input)
|
| 41 |
-
|
| 42 |
-
# Load your HTML UI
|
| 43 |
-
with open("index.html", "r") as html_file:
|
| 44 |
-
custom_html = html_file.read()
|
| 45 |
-
|
| 46 |
-
# Gradio App with Custom HTML
|
| 47 |
-
app = gr.Interface(
|
| 48 |
-
fn=chatbot,
|
| 49 |
-
inputs="text",
|
| 50 |
-
outputs="text",
|
| 51 |
-
title="Chatbot with Llama-3.3-70B",
|
| 52 |
-
)
|
| 53 |
-
|
| 54 |
-
# Add the HTML to the app
|
| 55 |
-
app.launch(
|
| 56 |
-
inline=True, # Embed the app into the HTML
|
| 57 |
-
share=True, # Make the app shareable
|
| 58 |
-
custom_html=custom_html, # Use the custom HTML file
|
| 59 |
-
)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
+
# Function to serve the HTML content
|
| 4 |
+
def display_html():
|
| 5 |
+
with open("index.html", "r") as file:
|
| 6 |
+
html_content = file.read()
|
| 7 |
+
return html_content
|
| 8 |
|
| 9 |
+
# Gradio interface with custom HTML rendering
|
| 10 |
+
interface = gr.Interface(
|
| 11 |
+
fn=display_html,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|