Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,28 +6,28 @@ from RAGModule import RAGModule
|
|
6 |
# Initialize the RAG module
|
7 |
RAG_Triwira = RAGModule()
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
def chat(message, chat_history):
|
30 |
-
|
31 |
# Define the Gradio interface
|
32 |
iface = gr.Interface(
|
33 |
fn=chat,
|
|
|
6 |
# Initialize the RAG module
|
7 |
RAG_Triwira = RAGModule()
|
8 |
|
9 |
+
def chat(message: str, chat_history: str):
|
10 |
+
prompt = RAG_Triwira.main(message)
|
11 |
+
url = "http://localhost:11434/api/generate"
|
12 |
+
payload = json.dumps({
|
13 |
+
"model": "ollama:latest", #"MarcoAland/llama3.1-rag-indo",
|
14 |
+
"prompt": prompt,
|
15 |
+
"format": "json",
|
16 |
+
"stream": False
|
17 |
+
})
|
18 |
+
headers = {
|
19 |
+
'Content-Type': 'application/json'
|
20 |
+
}
|
21 |
|
22 |
+
try:
|
23 |
+
response = requests.post(url, headers=headers, data=payload)
|
24 |
+
response.raise_for_status() # Raise an error for bad status codes
|
25 |
+
response_data = response.json()
|
26 |
+
return response_data.get('output', 'No response received')
|
27 |
+
except requests.exceptions.RequestException as e:
|
28 |
+
return f"Connection error: {e}"
|
29 |
+
# def chat(message, chat_history):
|
30 |
+
# yield "test"
|
31 |
# Define the Gradio interface
|
32 |
iface = gr.Interface(
|
33 |
fn=chat,
|