rishabh-gurbani commited on
Commit
64e129b
1 Parent(s): 9e0348d

added appliation

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +59 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .env
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import json
4
+ import requests
5
+ from dotenv import load_dotenv
6
+
7
+ load_dotenv()
8
+ backend_url = os.getenv("BACKEND_URL")
9
+ print(backend_url)
10
+
11
+ def format_messages(history:str):
12
+ converted_list = []
13
+
14
+ for item in history:
15
+ user_dict = {
16
+ "role": "user",
17
+ "parts": [item[0]]
18
+ }
19
+ model_dict = {
20
+ "role": "model",
21
+ "parts": [item[1]]
22
+ }
23
+ converted_list.append(user_dict)
24
+ converted_list.append(model_dict)
25
+
26
+ to_pass = {
27
+ "history" : converted_list
28
+ }
29
+
30
+ return to_pass
31
+
32
+ def get_completion(query, formatted_history):
33
+ print(formatted_history)
34
+ response = requests.post(f"{backend_url}/?q={query}", json=formatted_history)
35
+ print(response.json())
36
+ if response.status_code == 200:
37
+ return response.json()["completion"]
38
+ else:
39
+ return None
40
+
41
+ def yes_man(message, history):
42
+ formatted_messages = format_messages(history=history)
43
+ response = get_completion(query=message, formatted_history=formatted_messages)
44
+ return response
45
+
46
+
47
+ gr.ChatInterface(
48
+ yes_man,
49
+ chatbot=gr.Chatbot(height=500),
50
+ textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
51
+ title="Yes Man",
52
+ description="Ask Yes Man any question",
53
+ theme="soft",
54
+ examples=["Hello", "Am I cool?", "Are tomatoes vegetables?"],
55
+ cache_examples=True,
56
+ retry_btn=None,
57
+ undo_btn="Delete Previous",
58
+ clear_btn="Clear",
59
+ ).launch()