-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
43 lines (34 loc) · 1.08 KB
/
app.py
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
43
import requests
import json
import gradio as gr
url = "http://localhost:11434/api/generate"
headers = {
"Content-Type": "application/json"
}
history = []
def generate_response(prompt):
history.append(prompt)
final_prompt = "\n".join(history)
data = {
"model": "CodeEasy",
"prompt": final_prompt,
"stream": False
}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
response_text = response.text
data = json.loads(response_text)
actual_response = data["response"]
return actual_response
else:
return f"Error: {response.text}"
with gr.Blocks() as app:
gr.Markdown("## Code Assistant App Using Code Llama")
with gr.Row():
input_box = gr.Textbox(lines=4, placeholder="Enter your Prompt", label="Prompt")
output_box = gr.Textbox(label="Response")
submit_btn = gr.Button("Submit")
submit_btn.click(generate_response, inputs=input_box, outputs=output_box)
# Launch the app
if __name__ == "__main__":
app.launch(share=True)