Spaces:
Running
Running
File size: 1,606 Bytes
df56e64 7e723b7 41e22e7 b908c2d 41e22e7 e4e9f4c df56e64 e4e9f4c cdd8f1e df56e64 e4e9f4c 7e723b7 e4e9f4c 41e22e7 e4e9f4c 2346f85 41e22e7 cdd8f1e 41e22e7 2346f85 41e22e7 cdd8f1e 41e22e7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
from chromadb.utils import embedding_functions
import chromadb
from openai import OpenAI
import gradio as gr
import time
anyscale_base_url = "https://api.endpoints.anyscale.com/v1"
multilingual_embeddings = embedding_functions.SentenceTransformerEmbeddingFunction(model_name="jost/multilingual-e5-base-politics-de")
def predict(api_key, user_input):
client = chromadb.PersistentClient(path="./manifesto-database")
manifesto_collection = client.get_or_create_collection(name="manifesto-database", embedding_function=multilingual_embeddings)
prompt = f"""[INST] {user_input} [/INST]"""
client = OpenAI(base_url=anyscale_base_url, api_key=api_key)
completion = client.completions.create(
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
prompt=prompt,
temperature=0.7,
max_tokens=100)
response = completion.choices[0].text
return response
def main():
description = "This is a simple interface to interact with OpenAI’s Chat Completion API. Please enter your API key and your message."
with gr.Blocks() as demo:
with gr.Row():
api_key_input = gr.Textbox(label="API Key", placeholder="Enter your API key here", show_label=True, type="password")
user_input = gr.Textbox(label="Your Message", placeholder="Enter your message here")
submit_btn = gr.Button("Submit")
output = gr.Textbox(label="LLM Response")
submit_btn.click(fn=predict, inputs=[api_key_input, user_input], outputs=output)
demo.launch()
if __name__ == "__main__":
main()
|