Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import requests
|
| 3 |
-
import json
|
| 4 |
-
|
| 5 |
-
# Set the base URL of your vLLM server
|
| 6 |
-
BASE_URL = "https://q7i66ina1u82p8-8000.proxy.runpod.net/v1"
|
| 7 |
-
|
| 8 |
-
# Pre-configured model details
|
| 9 |
-
MODEL = "NousResearch/Meta-Llama-3-8B-Instruct"
|
| 10 |
-
|
| 11 |
-
def chat_with_model(user_message):
|
| 12 |
-
# Prepare the chat messages in JSON format
|
| 13 |
-
payload = {
|
| 14 |
-
"model": MODEL,
|
| 15 |
-
"messages": [
|
| 16 |
-
{"role": "system", "content": "You are a knowledgeable assistant."},
|
| 17 |
-
{"role": "user", "content": user_message}
|
| 18 |
-
]
|
| 19 |
-
}
|
| 20 |
-
|
| 21 |
-
# Headers to specify that the data sent is JSON
|
| 22 |
-
headers = {'Content-Type': 'application/json'}
|
| 23 |
-
|
| 24 |
-
# Make a POST request to the server
|
| 25 |
-
response = requests.post(f"{BASE_URL}/chat/completions", headers=headers, data=json.dumps(payload))
|
| 26 |
-
|
| 27 |
-
# Check if the request was successful
|
| 28 |
-
if response.status_code == 200:
|
| 29 |
-
return response.json()['choices'][0]['message']['content']
|
| 30 |
-
else:
|
| 31 |
-
return "Failed to retrieve response from the model: " + str(response.status_code)
|
| 32 |
-
|
| 33 |
-
# Define the Gradio interface
|
| 34 |
-
iface = gr.Interface(
|
| 35 |
-
fn=chat_with_model,
|
| 36 |
-
inputs=gr.Textbox(placeholder="Enter your message here..."),
|
| 37 |
-
outputs="text",
|
| 38 |
-
title="Chat with AI Model",
|
| 39 |
-
description="Send a message and get a response from a pre-configured AI model without knowing its details."
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
-
# Launch the application
|
| 43 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|