Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,39 @@
|
|
1 |
-
import requests
|
2 |
-
import json
|
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 |
-
data
|
29 |
-
actual_response
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
)
|
40 |
-
interface.launch()
|
|
|
1 |
+
import requests
|
2 |
+
import json
|
3 |
+
|
4 |
+
url="http://localhost:11434/api/generate"
|
5 |
+
|
6 |
+
headers={
|
7 |
+
|
8 |
+
'Content-Type':'application/json'
|
9 |
+
}
|
10 |
+
|
11 |
+
history=[]
|
12 |
+
|
13 |
+
def generate_response(prompt):
|
14 |
+
history.append(prompt)
|
15 |
+
final_prompt="\n".join(history)
|
16 |
+
|
17 |
+
data={
|
18 |
+
"model":"codingsensei",
|
19 |
+
"prompt":final_prompt,
|
20 |
+
"stream":False
|
21 |
+
}
|
22 |
+
|
23 |
+
response=requests.post(url,headers=headers,data=json.dumps(data))
|
24 |
+
|
25 |
+
if response.status_code==200:
|
26 |
+
response=response.text
|
27 |
+
data=json.loads(response)
|
28 |
+
actual_response=data['response']
|
29 |
+
return actual_response
|
30 |
+
else:
|
31 |
+
print("error:",response.text)
|
32 |
+
|
33 |
+
|
34 |
+
interface=gr.Interface(
|
35 |
+
fn=generate_response,
|
36 |
+
inputs=gr.Textbox(lines=4,placeholder="Enter your Prompt"),
|
37 |
+
outputs="text"
|
38 |
+
)
|
39 |
+
interface.launch()
|
|