Spaces:
Runtime error
Runtime error
as-cle-bert
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
+
from qdrant_client import QdrantClient
|
4 |
+
from load_encoder import encoder
|
5 |
+
from utils import NeuralSearcher
|
6 |
+
import spaces
|
7 |
+
import os
|
8 |
+
|
9 |
+
mytheme = gr.Theme.from_hub("JohnSmith9982/small_and_pretty")
|
10 |
+
|
11 |
+
collection_name = os.getenv("QDRANT_COLLECTION")
|
12 |
+
QDRANT_API_KEY = os.getenv("QDRANT_API")
|
13 |
+
QDRANT_URL = os.getenv("QDRANT_URL")
|
14 |
+
qdrant_client = QdrantClient(
|
15 |
+
url=QDRANT_URL,
|
16 |
+
api_key=QDRANT_API_KEY,
|
17 |
+
)
|
18 |
+
api_client = Client("eswardivi/Phi-3-mini-128k-instruct")
|
19 |
+
|
20 |
+
@spaces.GPU(duration=120)
|
21 |
+
def reply(message, history):
|
22 |
+
global encoder
|
23 |
+
global api_client
|
24 |
+
global qdrant_client
|
25 |
+
txt2txt = NeuralSearcher(collection_name, qdrant_client, encoder)
|
26 |
+
context = txt2txt.search(message)
|
27 |
+
to_phi = f"Instructions: you are a useful assistant focused on providing valuable content on Climate-related Financial Disclosures, and you should always give coincise and precise answers; Context: {context}; User prompt: {message}"
|
28 |
+
response = api_client.predict(
|
29 |
+
to_phi, # str in 'Message' Textbox component
|
30 |
+
0.2, # float (numeric value between 0 and 1) in 'Temperature' Slider component
|
31 |
+
True, # bool in 'Sampling' Checkbox component
|
32 |
+
512, # float (numeric value between 128 and 4096) in 'Max new tokens' Slider component
|
33 |
+
api_name="/chat"
|
34 |
+
)
|
35 |
+
return response
|
36 |
+
|
37 |
+
demo = gr.ChatInterface(fn=reply, title="Climate-related Financial Disclosures Counselor", theme=mytheme)
|
38 |
+
demo.launch(server_name="0.0.0.0", share=False)
|