Mohansai2004 commited on
Commit
0222994
·
1 Parent(s): 6e2a93c

feat: switch to deepseek model for token-free operation

Browse files
Files changed (1) hide show
  1. app.py +25 -5
app.py CHANGED
@@ -297,6 +297,22 @@ if 'PROGRAMMING_LANGUAGES' not in globals():
297
  }
298
  debug_info("Initialized PROGRAMMING_LANGUAGES")
299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
  def main():
301
  task = create_sidebar()
302
 
@@ -318,16 +334,20 @@ def main():
318
 
319
  if st.button("Analyze"):
320
  with st.spinner("Analyzing image..."):
321
- prompt = f"Analyze this image for {analysis_type}:"
322
- response = generate_response(prompt, image)
 
 
323
  st.write(response)
324
- else:
325
  concept = st.text_input("Enter the concept you want to understand:")
326
  if st.button("Explain"):
327
  if concept:
328
  with st.spinner("Generating explanation..."):
329
- prompt = f"Explain in detail: {concept}"
330
- response = generate_response(prompt)
 
 
331
  st.markdown(response)
332
 
333
  if __name__ == "__main__":
 
297
  }
298
  debug_info("Initialized PROGRAMMING_LANGUAGES")
299
 
300
+ def handle_text_generation(prompt, task_type="code"):
301
+ try:
302
+ model, tokenizer = load_model()
303
+ placeholder = st.empty()
304
+
305
+ if task_type == "code":
306
+ prompt = f"""Write professional code based on the given requirements.
307
+ Requirements: {prompt}"""
308
+ else:
309
+ prompt = f"Explain this concept: {prompt}"
310
+
311
+ return generate_response_streaming(prompt, model, tokenizer, placeholder)
312
+ except Exception as e:
313
+ debug_info(f"Error in text generation: {str(e)}")
314
+ return f"Error: {str(e)}"
315
+
316
  def main():
317
  task = create_sidebar()
318
 
 
334
 
335
  if st.button("Analyze"):
336
  with st.spinner("Analyzing image..."):
337
+ response = handle_text_generation(
338
+ f"Analyze this image for {analysis_type}:",
339
+ task_type="analysis"
340
+ )
341
  st.write(response)
342
+ else: # Concept Explanation
343
  concept = st.text_input("Enter the concept you want to understand:")
344
  if st.button("Explain"):
345
  if concept:
346
  with st.spinner("Generating explanation..."):
347
+ response = handle_text_generation(
348
+ concept,
349
+ task_type="explain"
350
+ )
351
  st.markdown(response)
352
 
353
  if __name__ == "__main__":