Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,55 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
import ollama
|
3 |
-
# import asyncio
|
4 |
-
# from openai import AsyncOpenAI
|
5 |
from RAGModule import RAGModule
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
# # Configure the async OpenAI client
|
11 |
-
# client = AsyncOpenAI(api_key="34.69.9.203", base_url="http://34.69.9.203:11434/v1")
|
12 |
-
|
13 |
-
# settings = {
|
14 |
-
# "model": "MarcoAland/llama3.1-rag-indo",
|
15 |
-
# "temperature": 0.3,
|
16 |
-
# "max_tokens": 2048,
|
17 |
-
# }
|
18 |
-
|
19 |
-
# async def generate_response(user_input: str) -> str:
|
20 |
-
# message = "Namamu adalah Mitrakara.\n\n" + user_input
|
21 |
-
# # Call documents options or not
|
22 |
-
# if "dokumen" in message.lower() or "document" in message.lower() or "documents" in message.lower():
|
23 |
-
# prompt = RAG_Trwira.main(message[10:])
|
24 |
-
# else:
|
25 |
-
# prompt = message
|
26 |
-
|
27 |
-
# # Format the messages as a list of message dictionaries
|
28 |
-
# message_formated = [
|
29 |
-
# {"role": "user", "content": prompt}
|
30 |
-
# ]
|
31 |
-
|
32 |
-
# # Use streaming to handle partial responses
|
33 |
-
# stream = await client.chat.completions.create(messages=message_formated, stream=True, **settings)
|
34 |
-
|
35 |
-
# response = ""
|
36 |
-
# async for part in stream:
|
37 |
-
# if token := part.choices[0].delta.content or "":
|
38 |
-
# response += token
|
39 |
-
|
40 |
-
# return response
|
41 |
-
|
42 |
-
# def chat(user_input: str):
|
43 |
-
# # Call the asynchronous response generation function
|
44 |
-
# response = asyncio.run(generate_response(user_input))
|
45 |
-
# return response
|
46 |
|
47 |
def chat(message: str, chat_history: str):
|
48 |
-
if "dokumen" in message.lower() or "document" in message.lower() or "documents" in message.lower():
|
49 |
-
|
50 |
-
else:
|
51 |
-
|
52 |
-
|
53 |
stream = ollama.chat(
|
54 |
model='MarcoAland/llama3.1-rag-indo',
|
55 |
messages=[{'role': 'user', 'content': prompt}],
|
@@ -64,12 +26,18 @@ def chat(message: str, chat_history: str):
|
|
64 |
# Define the Gradio interface
|
65 |
iface = gr.Interface(
|
66 |
fn=chat,
|
67 |
-
inputs=gr.Textbox(label="
|
68 |
outputs=gr.Textbox(label="Respons Mitrakara"),
|
69 |
title="Hai, namaku Mitrakara. Selamat datang!👋",
|
70 |
-
description=
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
)
|
72 |
|
73 |
# Launch the Gradio interface
|
74 |
if __name__ == "__main__":
|
75 |
-
iface.launch(share=False
|
|
|
1 |
import gradio as gr
|
2 |
import ollama
|
|
|
|
|
3 |
from RAGModule import RAGModule
|
4 |
|
5 |
+
ollama.pull("MarcoAland/llama3.1-rag-indo")
|
6 |
+
# Initialize the RAG module
|
7 |
+
RAG_Triwira = RAGModule()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
def chat(message: str, chat_history: str):
|
10 |
+
# if "dokumen" in message.lower() or "document" in message.lower() or "documents" in message.lower():
|
11 |
+
# prompt = RAG_Triwira.main(message[10:])
|
12 |
+
# else:
|
13 |
+
# prompt = message
|
14 |
+
prompt = RAG_Triwira.main(message)
|
15 |
stream = ollama.chat(
|
16 |
model='MarcoAland/llama3.1-rag-indo',
|
17 |
messages=[{'role': 'user', 'content': prompt}],
|
|
|
26 |
# Define the Gradio interface
|
27 |
iface = gr.Interface(
|
28 |
fn=chat,
|
29 |
+
inputs=gr.Textbox(label="Masukan pertanyaan anda", placeholder="Tanyakan saja padaku🌟"),
|
30 |
outputs=gr.Textbox(label="Respons Mitrakara"),
|
31 |
title="Hai, namaku Mitrakara. Selamat datang!👋",
|
32 |
+
description='''Berikut adalah beberapa tips untuk bertanya denganku✨✨✨\n1. Gunakan kata 'dokumen:' jika ingin bertanya mengenai dokumen/administrasi perusahaan.\n2. Gunakan kalimat tanya yang baik.\n3. Enjoy the conversation.😊'''
|
33 |
+
+ '''\n\nContoh penggunaan:\n1. Pertanyaan umum: "Beri saya 5 motivasi untuk menjadi pribadi yang lebih baik."\n2. Pertanyaan mengenai administrasi perusahaan: "Dokumen: Siapa nama ketua direksi dan apa saja tanggung jawab beliau."''',
|
34 |
+
examples=[
|
35 |
+
["Beri saya 5 motivasi untuk menjadi pribadi yang lebih baik."],
|
36 |
+
["Dokumen: Siapa nama ketua direksi dan apa saja tanggung jawab beliau."]
|
37 |
+
],
|
38 |
+
theme=gr.themes.Soft(),
|
39 |
)
|
40 |
|
41 |
# Launch the Gradio interface
|
42 |
if __name__ == "__main__":
|
43 |
+
iface.launch(share=True) # change "share=False" to make it private
|