Spaces:
Sleeping
Sleeping
Commit
·
b812301
1
Parent(s):
e447252
Update space
Browse files
app.py
CHANGED
@@ -1,35 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
3 |
|
4 |
-
# Fonction pour interroger Ollama
|
5 |
def query_ollama(prompt):
|
6 |
-
|
7 |
-
url = "http://localhost:11434/api/generate" # Le port utilisé par Ollama
|
8 |
-
model_name = "hf.co/ibrahimBlyc/LA_Llama:latest" # Nom complet du modèle
|
9 |
-
|
10 |
-
# Corps de la requête
|
11 |
payload = {
|
12 |
-
"model":
|
13 |
"prompt": prompt
|
14 |
}
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
# Interface Gradio
|
27 |
interface = gr.Interface(
|
28 |
fn=query_ollama,
|
29 |
-
inputs=gr.Textbox(label="
|
30 |
-
outputs=gr.Textbox(label="Réponse
|
31 |
-
title="
|
32 |
-
description="Une interface simple pour
|
33 |
)
|
34 |
|
35 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
+
import json
|
4 |
|
|
|
5 |
def query_ollama(prompt):
|
6 |
+
url = "http://localhost:11434/api/generate"
|
|
|
|
|
|
|
|
|
7 |
payload = {
|
8 |
+
"model": "hf.co/ibrahimBlyc/LA_Llama:latest",
|
9 |
"prompt": prompt
|
10 |
}
|
11 |
+
headers = {"Content-Type": "application/json"}
|
12 |
+
response = requests.post(url, json=payload, headers=headers, stream=True)
|
13 |
+
|
14 |
+
if response.status_code == 200:
|
15 |
+
full_response = ""
|
16 |
+
for line in response.iter_lines():
|
17 |
+
if line:
|
18 |
+
data = json.loads(line.decode("utf-8"))
|
19 |
+
if "response" in data:
|
20 |
+
full_response += data["response"]
|
21 |
+
if data.get("done", False):
|
22 |
+
break
|
23 |
+
return full_response
|
24 |
+
else:
|
25 |
+
return f"Erreur HTTP : {response.status_code}"
|
26 |
|
|
|
27 |
interface = gr.Interface(
|
28 |
fn=query_ollama,
|
29 |
+
inputs=gr.Textbox(label="Posez votre question"),
|
30 |
+
outputs=gr.Textbox(label="Réponse"),
|
31 |
+
title="Chat avec Ollama",
|
32 |
+
description="Une interface simple pour discuter avec le modèle hébergé sur Ollama."
|
33 |
)
|
34 |
|
35 |
if __name__ == "__main__":
|