Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
client =
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def chat(message):
|
| 8 |
-
try:
|
| 9 |
-
response = client.chat.completions.create(
|
| 10 |
-
model="gpt-4o-mini",
|
| 11 |
-
messages=[
|
| 12 |
-
{"role": "system", "content": "You are a helpful assistant."},
|
| 13 |
-
{"role": "user", "content": message}
|
| 14 |
-
]
|
| 15 |
-
)
|
| 16 |
-
return response.choices[0].message.content
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
iface = gr.Interface(
|
| 22 |
fn=chat,
|
| 23 |
-
inputs=
|
| 24 |
outputs="text",
|
| 25 |
title="AI Assistant",
|
| 26 |
-
description="
|
| 27 |
)
|
| 28 |
|
| 29 |
-
iface.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
|
|
|
| 3 |
|
| 4 |
+
client = InferenceClient(
|
| 5 |
+
model="mistralai/Mistral-7B-Instruct-v0.2"
|
| 6 |
+
)
|
| 7 |
|
| 8 |
def chat(message):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
response = client.text_generation(
|
| 11 |
+
message,
|
| 12 |
+
max_new_tokens=200
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
return response
|
| 16 |
+
|
| 17 |
|
| 18 |
iface = gr.Interface(
|
| 19 |
fn=chat,
|
| 20 |
+
inputs="text",
|
| 21 |
outputs="text",
|
| 22 |
title="AI Assistant",
|
| 23 |
+
description="Free AI assistant using Hugging Face"
|
| 24 |
)
|
| 25 |
|
| 26 |
+
iface.launch()
|