johann22 commited on
Commit
1623898
β€’
1 Parent(s): 527fffe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -19
app.py CHANGED
@@ -5,7 +5,8 @@ import gradio as gr
5
  from datetime import datetime
6
  import agent
7
  from models import models
8
- import urllib.request
 
9
  import uuid
10
  base_url="https://johann22-chat-diffusion.hf.space/"
11
 
@@ -54,30 +55,39 @@ def run_gpt(in_prompt,history):
54
 
55
 
56
  def run(purpose,history,model_drop):
 
 
 
 
 
57
  if history:
58
  history=str(history).strip("[]")
59
  if not history:
60
  history = ""
61
- try:
62
- out_prompt = run_gpt(purpose,history)
63
- out_prompt.strip()
64
- print (out_prompt)
65
- except Exception as e:
66
- out_prompt = f"An Error Occured generating the prompt \n {e}"
 
 
67
  yield ("",[(purpose,out_prompt)],None)
68
- try:
69
- #model=loaded_model[int(model_drop)]
70
- out_img=model(out_prompt)
71
- print(out_img)
72
- image=f'{base_url}file={out_img}'
73
- uid = uuid.uuid4()
74
- urllib.request.urlretrieve(image, f'{uid}.png')
75
- return ("",[(purpose,out_prompt)],f'{uid}.png')
76
-
77
- except Exception as e:
78
- print (e)
 
 
79
  #return ("", [(purpose,history)])
80
- return ("An Error Occured generating the image",[(purpose,out_prompt)],None)
81
 
82
 
83
 
 
5
  from datetime import datetime
6
  import agent
7
  from models import models
8
+ import requests
9
+ import io
10
  import uuid
11
  base_url="https://johann22-chat-diffusion.hf.space/"
12
 
 
55
 
56
 
57
  def run(purpose,history,model_drop):
58
+
59
+ #print(purpose)
60
+ #print(hist)
61
+ task=None
62
+ directory="./"
63
  if history:
64
  history=str(history).strip("[]")
65
  if not history:
66
  history = ""
67
+
68
+ #action_name, action_input = parse_action(line)
69
+ out_prompt = run_gpt(
70
+ purpose,
71
+ history,
72
+
73
+ )
74
+
75
  yield ("",[(purpose,out_prompt)],None)
76
+ #out_img = infer(out_prompt)
77
+ model=loaded_model[int(model_drop)]
78
+ out_img=model(out_prompt)
79
+ print(out_img)
80
+ url=f'https://johann22-chat-diffusion.hf.space/file={out_img}'
81
+ print(url)
82
+ uid = uuid.uuid4()
83
+ #urllib.request.urlretrieve(image, 'tmp.png')
84
+ #out=Image.open('tmp.png')
85
+ r = requests.get(url, stream=True)
86
+ if r.status_code == 200:
87
+ out = Image.open(io.BytesIO(r.content))
88
+ yield ("",[(purpose,out_prompt)],out)
89
  #return ("", [(purpose,history)])
90
+
91
 
92
 
93