Download app.py from arihilmir/example: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/arihilmir/example/resolve/main/app.py
- Command line
-
hf download hf://spaces/arihilmir/example/app.py
-
curl -L -o app.py https://huggingface.co/spaces/arihilmir/example/resolve/main/app.py
1.51 kB
| import gradio as gr | |
| from openai import OpenAI | |
| import os | |
| OPENAPI_ORG = os.getenv('OpenAPIOrganization') | |
| OPENAPI_PROJ = os.getenv('OpenAPIProject') | |
| client = OpenAI(organization=OPENAPI_ORG, project=OPENAPI_PROJ) | |
| class QuestionAnserBot: | |
| PROMPT = """\ | |
| You are a helpful assistant that can answer questions. | |
| Rules: | |
| - Reply with answer only and nothing but the answer | |
| - Say 'I don't know' if you don't know the answer | |
| - Use the provided context | |
| """ | |
| def answer_question(self, question: str) -> str: | |
| completion = client.chat.completions.create( | |
| model='gpt-3.5-turbo', | |
| messages=[ | |
| {'role': 'system', 'content': QuestionAnserBot.PROMPT}, | |
| {'role': 'user', 'content': f'Context:Кафдера систем штучного інтелекту. Місія кафедри: підготувати спеціаліста, який зможе вирішувати алгоритмічно складні задачі, аналізувати дані великих обсягів, розробляти алгоритми обробки відео, зображень або текстів, програмувати та керувати роботами\nQuestion:{question}'} | |
| ] | |
| ) | |
| return completion.choices[0].message.content | |
| def answer_question(query): | |
| bot = QuestionAnserBot() | |
| return bot.answer_question(query) | |
| demo = gr.Interface( | |
| fn=answer_question, | |
| inputs=["text"], | |
| outputs=["text"], | |
| ) | |
| demo.launch() |