Update app.py
Browse files
app.py
CHANGED
@@ -54,7 +54,7 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
54 |
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen1.5-1.8B-Chat")
|
55 |
|
56 |
|
57 |
-
|
58 |
try:
|
59 |
response = httpx.get(url, timeout=60.0)
|
60 |
response.raise_for_status()
|
@@ -66,7 +66,7 @@ async def validate_url(url):
|
|
66 |
except Exception as e:
|
67 |
return f"An unexpected error occurred: {str(e)}"
|
68 |
|
69 |
-
|
70 |
print("Entered Webpage Extraction")
|
71 |
prefix_url = "https://r.jina.ai/"
|
72 |
full_url = prefix_url + url
|
@@ -120,22 +120,7 @@ async def gen_show(script):
|
|
120 |
return output_filename
|
121 |
|
122 |
@spaces.GPU(duration=100)
|
123 |
-
def generator(
|
124 |
-
if not link.startswith("http://") and not link.startswith("https://"):
|
125 |
-
return "URL must start with 'http://' or 'https://'",None
|
126 |
-
|
127 |
-
text = fetch_text(link)
|
128 |
-
|
129 |
-
if "Error" in text:
|
130 |
-
return text, None
|
131 |
-
|
132 |
-
prompt = f"News: {text}, json:"
|
133 |
-
|
134 |
-
messages = [
|
135 |
-
{"role": "system", "content": system_prompt},
|
136 |
-
{"role": "user", "content": prompt},
|
137 |
-
]
|
138 |
-
|
139 |
answer = tokenizer.apply_chat_template(
|
140 |
messages,
|
141 |
tokenize=False,
|
@@ -153,8 +138,26 @@ def generator(link):
|
|
153 |
]
|
154 |
|
155 |
results = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
|
|
|
|
156 |
|
157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
|
159 |
print("Generated Script:"+generated_script)
|
160 |
|
@@ -182,7 +185,7 @@ with gr.Blocks(theme='soft', css=css, title="Musen") as iface:
|
|
182 |
clear_btn = gr.ClearButton(output_box, value="🗑️ Clear") # Create a clear button
|
183 |
|
184 |
# Set up the event listeners
|
185 |
-
submit_btn.click(
|
186 |
|
187 |
|
188 |
#gr.close_all()
|
|
|
54 |
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen1.5-1.8B-Chat")
|
55 |
|
56 |
|
57 |
+
def validate_url(url):
|
58 |
try:
|
59 |
response = httpx.get(url, timeout=60.0)
|
60 |
response.raise_for_status()
|
|
|
66 |
except Exception as e:
|
67 |
return f"An unexpected error occurred: {str(e)}"
|
68 |
|
69 |
+
def fetch_text(url):
|
70 |
print("Entered Webpage Extraction")
|
71 |
prefix_url = "https://r.jina.ai/"
|
72 |
full_url = prefix_url + url
|
|
|
120 |
return output_filename
|
121 |
|
122 |
@spaces.GPU(duration=100)
|
123 |
+
def generator(messages):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
answer = tokenizer.apply_chat_template(
|
125 |
messages,
|
126 |
tokenize=False,
|
|
|
138 |
]
|
139 |
|
140 |
results = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
141 |
+
return results
|
142 |
+
|
143 |
|
144 |
+
async def main(link):
|
145 |
+
if not link.startswith("http://") and not link.startswith("https://"):
|
146 |
+
return "URL must start with 'http://' or 'https://'",None
|
147 |
+
|
148 |
+
text = fetch_text(link)
|
149 |
+
|
150 |
+
if "Error" in text:
|
151 |
+
return text, None
|
152 |
+
|
153 |
+
prompt = f"News: {text}, json:"
|
154 |
+
|
155 |
+
messages = [
|
156 |
+
{"role": "system", "content": system_prompt},
|
157 |
+
{"role": "user", "content": prompt},
|
158 |
+
]
|
159 |
+
|
160 |
+
generated_script = generator(messages)
|
161 |
|
162 |
print("Generated Script:"+generated_script)
|
163 |
|
|
|
185 |
clear_btn = gr.ClearButton(output_box, value="🗑️ Clear") # Create a clear button
|
186 |
|
187 |
# Set up the event listeners
|
188 |
+
submit_btn.click(main, inputs=input_box, outputs=output_box)
|
189 |
|
190 |
|
191 |
#gr.close_all()
|