Delete app.py
Browse files
app.py
DELETED
|
@@ -1,89 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from huggingface_hub import InferenceClient
|
| 3 |
-
|
| 4 |
-
"""
|
| 5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
-
"""
|
| 7 |
-
client = InferenceClient("meta-llama/Llama-3.2-3B-Instruct")
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def respond(
|
| 11 |
-
model_name,
|
| 12 |
-
message,
|
| 13 |
-
history: list[tuple[str, str]],
|
| 14 |
-
system_message,
|
| 15 |
-
):
|
| 16 |
-
messages = [{"role": "system", "content": system_message}]
|
| 17 |
-
|
| 18 |
-
for val in history:
|
| 19 |
-
if val[0]:
|
| 20 |
-
messages.append({"role": "user", "content": val[0]})
|
| 21 |
-
if val[1]:
|
| 22 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 23 |
-
|
| 24 |
-
messages.append({"role": "user", "content": message})
|
| 25 |
-
|
| 26 |
-
response = ""
|
| 27 |
-
|
| 28 |
-
# Model selection based on the button click
|
| 29 |
-
if model_name == "Llama":
|
| 30 |
-
for message in client.chat_completion(
|
| 31 |
-
messages,
|
| 32 |
-
max_tokens=512, # Set a default value for max_tokens
|
| 33 |
-
stream=True,
|
| 34 |
-
temperature=0.7, # Set a default value for temperature
|
| 35 |
-
top_p=0.95, # Set a default value for top_p
|
| 36 |
-
):
|
| 37 |
-
token = message.choices[0].delta.content
|
| 38 |
-
response += token
|
| 39 |
-
elif model_name == "Chatgpt":
|
| 40 |
-
response = "ChatGPT functionality is not yet implemented."
|
| 41 |
-
elif model_name == "Claude":
|
| 42 |
-
response = "Claude functionality is not yet implemented."
|
| 43 |
-
else:
|
| 44 |
-
response = "Model not recognized."
|
| 45 |
-
|
| 46 |
-
return response
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
# CSS for styling the interface
|
| 50 |
-
css = """
|
| 51 |
-
body {
|
| 52 |
-
background-color: #06688E; /* Dark background */
|
| 53 |
-
color: white; /* Text color for better visibility */
|
| 54 |
-
}
|
| 55 |
-
.gr-button {
|
| 56 |
-
background-color: #42B3CE !important; /* White button color */
|
| 57 |
-
color: black !important; /* Black text for contrast */
|
| 58 |
-
border: none !important;
|
| 59 |
-
padding: 8px 16px !important;
|
| 60 |
-
border-radius: 5px !important;
|
| 61 |
-
}
|
| 62 |
-
.gr-button:hover {
|
| 63 |
-
background-color: #e0e0e0 !important; /* Slightly lighter button on hover */
|
| 64 |
-
}
|
| 65 |
-
.gr-slider-container {
|
| 66 |
-
color: white !important; /* Slider labels in white */
|
| 67 |
-
}
|
| 68 |
-
"""
|
| 69 |
-
|
| 70 |
-
# Define the Gradio interface with buttons and model selection
|
| 71 |
-
def gradio_interface(model_name, message, history, system_message):
|
| 72 |
-
return respond(model_name, message, history, system_message)
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
demo = gr.Interface(
|
| 76 |
-
fn=gradio_interface,
|
| 77 |
-
inputs=[
|
| 78 |
-
gr.Textbox(value="Hello!", label="User Message"),
|
| 79 |
-
gr.Textbox(value="You are a virtual health assistant. Your primary goal is to assist with health-related queries.", label="System Message", visible=False),
|
| 80 |
-
gr.Button("Chatgpt"),
|
| 81 |
-
gr.Button("Llama"),
|
| 82 |
-
gr.Button("Claude"),
|
| 83 |
-
],
|
| 84 |
-
outputs="text",
|
| 85 |
-
css=css, # Pass the custom CSS here
|
| 86 |
-
)
|
| 87 |
-
|
| 88 |
-
if __name__ == "__main__":
|
| 89 |
-
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|