Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,36 +7,47 @@ import time
|
|
| 7 |
anyscale_base_url = "https://api.endpoints.anyscale.com/v1"
|
| 8 |
multilingual_embeddings = embedding_functions.SentenceTransformerEmbeddingFunction(model_name="jost/multilingual-e5-base-politics-de")
|
| 9 |
|
| 10 |
-
def predict(api_key, user_input):
|
| 11 |
-
client = chromadb.PersistentClient(path="./manifesto-database")
|
| 12 |
-
manifesto_collection = client.get_or_create_collection(name="manifesto-database", embedding_function=multilingual_embeddings)
|
| 13 |
-
retrieved_context = manifesto_collection.query(query_texts=[user_input], n_results=3, where={"ideology": "Authoritarian-right"})
|
| 14 |
-
contexts = [context for context in retrieved_context['documents']]
|
| 15 |
-
print(contexts[0])
|
| 16 |
|
| 17 |
prompt = f"""[INST] {user_input} [/INST]"""
|
| 18 |
|
| 19 |
client = OpenAI(base_url=anyscale_base_url, api_key=api_key)
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
prompt=prompt,
|
| 23 |
temperature=0.7,
|
| 24 |
-
max_tokens=1000)
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
def main():
|
| 30 |
description = "This is a simple interface to interact with OpenAI’s Chat Completion API. Please enter your API key and your message."
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
with gr.Row():
|
| 33 |
api_key_input = gr.Textbox(label="API Key", placeholder="Enter your API key here", show_label=True, type="password")
|
| 34 |
user_input = gr.Textbox(label="Your Message", placeholder="Enter your message here")
|
|
|
|
|
|
|
| 35 |
submit_btn = gr.Button("Submit")
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
submit_btn.click(fn=predict, inputs=[api_key_input, user_input], outputs=
|
| 40 |
|
| 41 |
demo.launch()
|
| 42 |
|
|
|
|
| 7 |
anyscale_base_url = "https://api.endpoints.anyscale.com/v1"
|
| 8 |
multilingual_embeddings = embedding_functions.SentenceTransformerEmbeddingFunction(model_name="jost/multilingual-e5-base-politics-de")
|
| 9 |
|
| 10 |
+
def predict(api_key, user_input, model1, model2):
|
| 11 |
+
# client = chromadb.PersistentClient(path="./manifesto-database")
|
| 12 |
+
# manifesto_collection = client.get_or_create_collection(name="manifesto-database", embedding_function=multilingual_embeddings)
|
| 13 |
+
# retrieved_context = manifesto_collection.query(query_texts=[user_input], n_results=3, where={"ideology": "Authoritarian-right"})
|
| 14 |
+
# contexts = [context for context in retrieved_context['documents']]
|
| 15 |
+
# print(contexts[0])
|
| 16 |
|
| 17 |
prompt = f"""[INST] {user_input} [/INST]"""
|
| 18 |
|
| 19 |
client = OpenAI(base_url=anyscale_base_url, api_key=api_key)
|
| 20 |
+
|
| 21 |
+
response1 = client.completions.create(
|
| 22 |
+
model=model1,
|
| 23 |
prompt=prompt,
|
| 24 |
temperature=0.7,
|
| 25 |
+
max_tokens=1000).choices[0].text
|
| 26 |
|
| 27 |
+
response2 = client.completions.create(
|
| 28 |
+
model=model2,
|
| 29 |
+
prompt=prompt,
|
| 30 |
+
temperature=0.7,
|
| 31 |
+
max_tokens=1000).choices[0].text
|
| 32 |
|
| 33 |
+
return response1, response2
|
| 34 |
+
|
| 35 |
+
|
| 36 |
def main():
|
| 37 |
description = "This is a simple interface to interact with OpenAI’s Chat Completion API. Please enter your API key and your message."
|
| 38 |
with gr.Blocks() as demo:
|
| 39 |
with gr.Row():
|
| 40 |
api_key_input = gr.Textbox(label="API Key", placeholder="Enter your API key here", show_label=True, type="password")
|
| 41 |
user_input = gr.Textbox(label="Your Message", placeholder="Enter your message here")
|
| 42 |
+
model_selector1 = gr.Dropdown(label="Model 1", choices=["mistralai/Mixtral-8x7B-Instruct-v0.1", "mistralai/Mixtral-8x22B-Instruct-v0.1"])
|
| 43 |
+
model_selector2 = gr.Dropdown(label="Model 2", choices=["mistralai/Mixtral-8x7B-Instruct-v0.1", "mistralai/Mixtral-8x22B-Instruct-v0.1"])
|
| 44 |
submit_btn = gr.Button("Submit")
|
| 45 |
|
| 46 |
+
output1 = gr.Textbox(label="Model 1 Response")
|
| 47 |
+
output2 = gr.Textbox(label="Model 2 Response")
|
| 48 |
+
|
| 49 |
|
| 50 |
+
submit_btn.click(fn=predict, inputs=[api_key_input, user_input, model_selector1, model_selector2], outputs=[output1, output2])
|
| 51 |
|
| 52 |
demo.launch()
|
| 53 |
|