Spaces:
Runtime error
Runtime error
TA
commited on
Commit
·
ef43705
1
Parent(s):
db3925a
Update app.py
Browse files
app.py
CHANGED
@@ -10,74 +10,61 @@ EXAMPLE_INPUT = "A Reflective cat between stars."
|
|
10 |
enticing_image_path = "C:/Users/alain/Downloads/enticing_image.jpg"
|
11 |
|
12 |
html_temp = """
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
</div>
|
21 |
-
""".format(TITLE, enticing_image_path, EXAMPLE_INPUT)
|
22 |
-
|
23 |
-
zephyr_7b_beta = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta/"
|
24 |
-
|
25 |
-
HF_TOKEN = os.getenv("HF_TOKEN")
|
26 |
-
HEADERS = {"Authorization": f"Bearer {HF_TOKEN}"}
|
27 |
-
|
28 |
-
def build_input_prompt(message, chatbot, system_prompt):
|
29 |
-
input_prompt = "\n" + system_prompt + "</s>\n\n"
|
30 |
-
for interaction in chatbot:
|
31 |
-
input_prompt = input_prompt + str(interaction[0]) + "</s>\n\n" + str(interaction[1]) + "\n</s>\n\n"
|
32 |
-
|
33 |
-
input_prompt = input_prompt + str(message) + "</s>\n"
|
34 |
-
return input_prompt
|
35 |
-
|
36 |
-
def post_request_beta(payload):
|
37 |
-
response = requests.post(zephyr_7b_beta, headers=HEADERS, json=payload)
|
38 |
-
response.raise_for_status()
|
39 |
-
return response.json()
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
45 |
}
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
if 'generated_text' in json_obj and len(json_obj['generated_text']) > 0:
|
52 |
-
bot_message = json_obj['generated_text']
|
53 |
-
return bot_message
|
54 |
-
elif 'error' in json_obj:
|
55 |
-
raise gr.Error(json_obj['error'] + ' Please refresh and try again with smaller input prompt')
|
56 |
-
else:
|
57 |
-
warning_msg = f"Unexpected response: {json_obj}"
|
58 |
-
raise gr.Error(warning_msg)
|
59 |
-
except requests.HTTPError as e:
|
60 |
-
error_msg = f"Request failed with status code {e.response.status_code}"
|
61 |
-
raise gr.Error(error_msg)
|
62 |
-
except json.JSONDecodeError as e:
|
63 |
-
error_msg = f"Failed to decode response as JSON: {str(e)}"
|
64 |
-
raise gr.Error(error_msg)
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
71 |
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
74 |
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
-
|
79 |
-
textbox_preview = gr.Textbox(scale=7, container=False, value=EXAMPLE_INPUT)
|
80 |
|
81 |
-
demo = gr.ChatInterface(test_preview_chatbot, chatbot=chatbot_preview, textbox=textbox_preview)
|
82 |
|
83 |
demo.launch(share=True)
|
|
|
10 |
enticing_image_path = "C:/Users/alain/Downloads/enticing_image.jpg"
|
11 |
|
12 |
html_temp = """
|
13 |
+
<!DOCTYPE html>
|
14 |
+
<html>
|
15 |
+
<head>
|
16 |
+
<style>
|
17 |
+
body {
|
18 |
+
font-family: Arial, sans-serif;
|
19 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
.container {
|
22 |
+
text-align: center;
|
23 |
+
background-color: #f4f4f4;
|
24 |
+
padding: 20px;
|
25 |
+
border-radius: 10px;
|
26 |
}
|
27 |
|
28 |
+
h1 {
|
29 |
+
color: #333;
|
30 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
.enticing-image {
|
33 |
+
width: 100px;
|
34 |
+
height: 100px;
|
35 |
+
border-radius: 50%;
|
36 |
+
position: absolute;
|
37 |
+
top: 0;
|
38 |
+
right: 0;
|
39 |
+
}
|
40 |
|
41 |
+
.main-image {
|
42 |
+
width: 300px;
|
43 |
+
height: 300px;
|
44 |
+
border-radius: 50%;
|
45 |
+
}
|
46 |
|
47 |
+
p {
|
48 |
+
font-size: 18px;
|
49 |
+
color: #555;
|
50 |
+
}
|
51 |
+
</style>
|
52 |
+
</head>
|
53 |
+
<body>
|
54 |
+
<div class="container">
|
55 |
+
<h1>{}</h1>
|
56 |
+
<div class="enticing-image">
|
57 |
+
<img src='{}' alt='Enticing Image'>
|
58 |
+
</div>
|
59 |
+
<img class="main-image" src='https://huggingface.co/spaces/NerdN/open-gpt-Image-Prompter/blob/main/_45a03b4d-ea0f-4b81-873d-ff6b10461d52.jpg' alt='Your Image'>
|
60 |
+
<p>{}</p>
|
61 |
+
</div>
|
62 |
+
</body>
|
63 |
+
</html>
|
64 |
+
""".format(TITLE, enticing_image_path, EXAMPLE_INPUT)
|
65 |
|
66 |
+
# Rest of the code remains unchanged
|
|
|
67 |
|
68 |
+
demo = gr.ChatInterface(test_preview_chatbot, chatbot=chatbot_preview, textbox=textbox_preview, title=None, html=html_temp)
|
69 |
|
70 |
demo.launch(share=True)
|